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; + } + } } } }