From 0d1e4d99230e28e125cbf6611b0ae0295eace434 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Tue, 9 Jan 2024 06:33:34 -0700 Subject: [PATCH] Setting variable on entity instance now looks to Entity's variable for the type fixes #1302 --- .../NamedObjectSaveExtensionMethods.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/FRBDK/Glue/Glue/SaveClasses/NamedObjectSaveExtensionMethods.cs b/FRBDK/Glue/Glue/SaveClasses/NamedObjectSaveExtensionMethods.cs index 5bcc45a50..21a4b90a0 100644 --- a/FRBDK/Glue/Glue/SaveClasses/NamedObjectSaveExtensionMethods.cs +++ b/FRBDK/Glue/Glue/SaveClasses/NamedObjectSaveExtensionMethods.cs @@ -510,8 +510,20 @@ public static void SetVariable(this NamedObjectSave instance, string variableNam } else { - var type = value?.GetType(); - instruction = instance.AddNewGenericInstructionFor(variableName, type); + // If it comes from an entity, try to assign the type from the entity. This is needed if the variable + // is an Entity.Type property + var nosEntity = ObjectFinder.Self.GetEntitySave(instance); + var variable = nosEntity?.GetCustomVariableRecursively(variableName); + + if(variable != null) + { + instruction = instance.AddInstruction(variableName, variable.Type); + } + else + { + var type = value?.GetType(); + instruction = instance.AddNewGenericInstructionFor(variableName, type); + } } }