signals
signals copied to clipboard
Not Compatible with Domain Reloading turned off
Right now, if you turn off Unity's Domain Reloading checkbox, you'll get duplicate listeners on your SignalHub because it's not getting refreshed between play modes.
I made a simple change in my project that fixes this:
First, add a using statement for UnityEditor when you're in the editor:
#if UNITY_EDITOR
using UnityEditor;
#endif
Then, in the static Signals class, replace the hub initialization line with this:
private static SignalHub hub = new SignalHub();
#if UNITY_EDITOR
[InitializeOnEnterPlayMode]
private static void ResetSignalHub()
{
hub = new SignalHub();
}
#endif
This requires removing the readonly keyword from the static hub, but it's already private in a small static class, so nothing else can get to it and reset it anyway.
This will make sure that the static hub gets re-initialized on play mode enter even if domain reloading is turned off.