From 1f9f281c317b2f343c5796e67142bec30acb3e5d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 10 Feb 2026 15:02:05 +0100 Subject: [PATCH] Fix regression from 7b7a92758ff1a6f040c535b8e5a8858dd36d7380 for Visual Scripts --- Source/Engine/Content/Assets/VisualScript.cpp | 2 ++ Source/Engine/Core/Types/Variant.cpp | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index 329696dea..a7e132bdc 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -1700,6 +1700,8 @@ void VisualScript::CacheScriptingType() VisualScriptingBinaryModule::VisualScriptingBinaryModule() : _name("Visual Scripting") { + // Visual Scripts can be unloaded and loaded again even in game + CanReload = true; } ScriptingObject* VisualScriptingBinaryModule::VisualScriptObjectSpawn(const ScriptingObjectSpawnParams& params) diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index bd2d594df..dcabe8e48 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -35,13 +35,6 @@ #endif #define AsEnum AsUint64 -// Editor can hot-reload assemblies thus cached type names may become invalid, otherwise use modules that are never unloaded and their type names are always valid -#if USE_EDITOR -#define IS_VARIANT_TYPE_NAME_STATIC(canReload) !canReload -#else -#define IS_VARIANT_TYPE_NAME_STATIC(canReload) true -#endif - namespace { const char* InBuiltTypesTypeNames[40] = @@ -352,13 +345,13 @@ void VariantType::SetTypeName(const StringAnsiView& typeName, bool staticName) void VariantType::SetTypeName(const ScriptingType& type) { - SetTypeName(type.Fullname, IS_VARIANT_TYPE_NAME_STATIC(type.Module->CanReload)); + SetTypeName(type.Fullname, type.Module->CanReload); } void VariantType::SetTypeName(const MClass& klass) { #if USE_CSHARP - SetTypeName(klass.GetFullName(), IS_VARIANT_TYPE_NAME_STATIC(klass.GetAssembly()->CanReload())); + SetTypeName(klass.GetFullName(), klass.GetAssembly()->CanReload()); #endif } @@ -385,11 +378,23 @@ VariantType VariantType::GetElementType() const void VariantType::Inline() { - const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(TypeName); - if (typeHandle) - SetTypeName(typeHandle.GetType()); + // Check if the typename comes from static assembly which can be used to inline name instead of dynamic memory allocation + StringAnsiView typeName(TypeName); + auto& modules = BinaryModule::GetModules(); + for (auto module : modules) + { + int32 typeIndex; + if (!module->CanReload && module->FindScriptingType(typeName, typeIndex)) + { + ScriptingTypeHandle typeHandle(module, typeIndex); + SetTypeName(typeHandle.GetType().Fullname, true); + return; + } + } + #if USE_CSHARP - else if (const auto mclass = Scripting::FindClass(TypeName)) + // Try with C#-only types + if (const auto mclass = Scripting::FindClass(TypeName)) SetTypeName(*mclass); #endif }