From b7cc4c768f4ba186376f0e03d804d3aa052970e4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 10 Jan 2024 12:08:01 +0100 Subject: [PATCH] Fix unpacking `Variant` structure if input value is a scalar #2163 --- Source/Engine/Core/Types/Variant.cpp | 18 ++++++++++++++++++ Source/Engine/Visject/VisjectGraph.cpp | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index 66e17b0a2..9e8b69b2c 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -139,6 +139,24 @@ VariantType::VariantType(const StringAnsiView& typeName) return; } } + { + // Aliases + if (typeName == "FlaxEngine.Vector2") + { + new(this) VariantType(Vector2); + return; + } + if (typeName == "FlaxEngine.Vector3") + { + new(this) VariantType(Vector3); + return; + } + if (typeName == "FlaxEngine.Vector4") + { + new(this) VariantType(Vector4); + return; + } + } // Check case for array if (typeName.EndsWith(StringAnsiView("[]"), StringSearchCase::CaseSensitive)) diff --git a/Source/Engine/Visject/VisjectGraph.cpp b/Source/Engine/Visject/VisjectGraph.cpp index 64164ecec..ea2824e77 100644 --- a/Source/Engine/Visject/VisjectGraph.cpp +++ b/Source/Engine/Visject/VisjectGraph.cpp @@ -685,9 +685,9 @@ void VisjectExecutor::ProcessGroupPacking(Box* box, Node* node, Value& value) case 36: { // Get value with structure data - Variant structureValue = eatBox(node, node->GetBox(0)->FirstConnection()); if (!node->GetBox(0)->HasConnection()) return; + Variant structureValue = eatBox(node, node->GetBox(0)->FirstConnection()); // Find type const StringView typeName(node->Values[0]); @@ -741,6 +741,12 @@ void VisjectExecutor::ProcessGroupPacking(Box* box, Node* node, Value& value) return; } const ScriptingType& type = typeHandle.GetType(); + if (structureValue.Type.Type != VariantType::Structure) // If structureValue is eg. Float we can try to cast it to a required structure type + { + VariantType typeVariantType(typeNameAnsiView); + if (Variant::CanCast(structureValue, typeVariantType)) + structureValue = Variant::Cast(structureValue, typeVariantType); + } structureValue.InvertInline(); // Extract any Float3/Int32 into Structure type from inlined format const ScriptingTypeHandle structureValueTypeHandle = Scripting::FindScriptingType(structureValue.Type.GetTypeName()); if (structureValue.Type.Type != VariantType::Structure || typeHandle != structureValueTypeHandle)