Skip to content

fix: NetworkManager doesn't destroy itself on multi instance #765

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

Merged
merged 16 commits into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,6 @@ private void Awake()

private void OnEnable()
{
if (Singleton != null && Singleton != this)
{
Destroy(gameObject);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with what this code does, but when I read the PR title I anticipated to see "if multi-scene, don't destroy, else still do" but what I see here is we don't destroy the game object anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it makes no sense for us to destroy it. I can't remember why I did it that way.

Basically what this used to do was:

If there was a NetworkManager already, destroy myself.

Now it doesn't destroy it anymore. That's the only difference.

return;
}

SetSingleton();

if (DontDestroy)
{
DontDestroyOnLoad(gameObject);
Expand All @@ -736,13 +728,19 @@ private void OnEnable()
{
Application.runInBackground = true;
}

if (Singleton == null)
{
SetSingleton();
}
}

private void OnDestroy()
{
if (Singleton != null && Singleton == this)
Shutdown();

if (Singleton == this)
{
Shutdown();
Singleton = null;
}
}
Expand Down