From 54de32020a70912027154929260fd7a5e7aebb91 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Wed, 31 Jan 2024 21:09:37 -0700 Subject: [PATCH] State variables that reference missing states no longer codegen fixes #1341 --- .../CodeGeneration/StateCodeGenerator.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/StateCodeGenerator.cs b/FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/StateCodeGenerator.cs index db21dc556..013c69b63 100644 --- a/FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/StateCodeGenerator.cs +++ b/FRBDK/Glue/GumPlugin/GumPlugin/CodeGeneration/StateCodeGenerator.cs @@ -423,8 +423,11 @@ private bool GetIfShouldGenerateStateVariable(Gum.DataTypes.Variables.VariableSa { toReturn = false; } + + var isVariableState = variable.IsState(container); + // states can't set states on this - if(variable.IsState(container) && string.IsNullOrEmpty(variable.SourceObject ) ) + if(isVariableState && string.IsNullOrEmpty(variable.SourceObject ) ) { toReturn = false; } @@ -489,6 +492,19 @@ private bool GetIfShouldGenerateStateVariable(Gum.DataTypes.Variables.VariableSa // This doesn't exist anywhere in the inheritance chain, so we don't want to generate it: toReturn = false; } + + if(isVariableState) + { + // see if the base type has this category. If so, see if the state name exists. If not, we should skip generation: + var category = baseElement.Categories.FirstOrDefault(item => item.Name == variable.Type); + var variableValueAsString = variable.Value?.ToString(); + + if(!string.IsNullOrEmpty(variableValueAsString) && category != null && !category.States.Any(item => item.Name == variableValueAsString)) + { + // this references an invalid state. This can happen if a state is deleted from an entity + toReturn = false; + } + } } } }