Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Compatible with Domain Reloading turned off #2

Open
NickMercer opened this issue Apr 10, 2022 · 0 comments
Open

Not Compatible with Domain Reloading turned off #2

NickMercer opened this issue Apr 10, 2022 · 0 comments

Comments

@NickMercer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant