Skip to content

Commit

Permalink
State variables that reference missing states no longer codegen
Browse files Browse the repository at this point in the history
fixes #1341
  • Loading branch information
vchelaru committed Feb 1, 2024
1 parent 4f5c541 commit 54de320
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
}
}
Expand Down

0 comments on commit 54de320

Please sign in to comment.