Just a tip for anyone else that might have missed this.
I started using delegates/events some time ago and picked up that when you add an event listener, you should also keep things clean and remove it when the listening object is destroyed. It was suggested at the time that using OnEnable and OnDisable were good places to do this, eg.
private void OnEnable()
{
UnitActionSystem.Instance.OnBusyChanged +=
UnitActionSystem_OnBusyChanged;
}
private void OnDisable()
{
UnitActionSystem.Instance.OnBusyChanged -=
UnitActionSystem_OnBusyChanged;
}
The problem in this case is that the ActionBusyUI adds the listener at runtime, but after the first call to gameObject.SetActive(false)
, it is removed, because that triggers OnDisable()
.
In this case, I moved the de-registration call into the Destroy()
method.