-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Is your feature request related to a problem? Please describe.
There are scenarios in which nested StatefulComponents have not yet undergone their Awake/OnEnable methods before being referenced, such as when a parent gameObject is activated and requests nestedComponent.SetState() in its OnEnable method.
This throws a Null Reference Exception because the StateProcessor for the nested StatefulComponent has not yet been created.
Describe the solution you'd like
The StatefulComponent should handle its own dependencies irrespective of script execution order. Maybe via field backing. ie:
private StateProcessor _sP;
private StateProcessor _stateProcessor
{
get
{
_sP ??= new StateProcessor(this);
return _sP;
}
}
Describe alternatives you've considered
- adding [DefaultExecutionOrder(-1)] to the StatefulComponent
- successfully solved the issue. unsure if this raises backwards compatibility issues
- adding [DefaultExecutionOrder(+1)] to all parent scripts
- successfully solved the issue and is the solution I'm currently using, but doesn't fix the problem for other users
- using the StatefulComponents initial State setting
- not successful because not all instances of a prefab always share the same initial state
Additional context
I'm unsure about the inner workings of the StateProcessor and whether it has dependencies on the Awake/Enable methods of the StatefulComponent