- Home /
OnEnable - Script Hot Reload - Script Execution Order
Hi,
I have a script A with an execution order set to -500.
I have a script B with no script execution order set (default time)
The order of the OnEnable calls are the following when pressing play (it's fine):
A OnEnable
B OnEnable
I'm changing some code while playing. Once Unity has finished recompiling, the following calls are done:
B OnEnable
A OnEnable
I would have expected the follwing order (same has the initial order):
A OnEnable
B OnEnable
My goal is to have the script B listen to an event of A, and make sure the event is still register after the script recompilation:
public class B : MonoBehaviour
{
protected void OnEnable()
{
Debug.Log("B OnEnable ");
A.Instance.MyEvent.AddListener(OnAEvent);
}
}
I'm using Unity 5.5.0f3
Thanks!
It has been a long while since I trusted hot reloading: it just always messed up and gave me errors. I'm surprised it works for others, but I'd recommend not to rely on it too much.
Answer by hexagonius · May 20, 2018 at 03:05 PM
I recommend you to report that as a bug. nothing from the documentation says anything about this anomaly when hot loading.
Thanks for confir$$anonymous$$g, that it's not stated in the documentation. I sent a Bug Report ( https://fogbugz.unity3d.com/default.asp?1040132_rpv91mrd90ans55h ) and later noticed that there was already one pending ( https://issuetracker.unity3d.com/issues/scriptexecutionorder-ignored-when-reloading-scripts-during-playmode )