Description
Summary
Forum user Kulko reported a potential editor bug where Components added to a GameObject during the Activate call don't show up in the Scene View and overall seem to throw the editor into an inconsistent state.
Before I checked for being in the editor this got automatically run when adding the controller component to the game Object. So with adding one component I automatically added two. However in the scene tree only the second component (InitState) gets displayed and I had to deactivate components and reactivate components in order to see the controller. In the properties Pane both components are shown correctly.
Bonus Bug: I was not able to delete the reference to the InitState from the Controller via the red cross.
Investigate.
How to reproduce
The following code was posted as an example to reproduce this bug:
public void OnInit(InitContext context)
{
if (context == InitContext.Activate)
{
ChangeState<InitBattleState>();
}
}
public virtual void ChangeState<T>() where T : State, new()
{
CurrentState = GetState<T>();
}
public virtual T GetState<T>() where T : State , new()
{
T target = GameObj.GetComponent<T>();
if (target == null)
target = GameObj.AddComponent<T>();
return target;
}