Skip to content

Commit

Permalink
fix: fixing null ref when ObjectManager not set
Browse files Browse the repository at this point in the history
ObjectManager is optional
  • Loading branch information
James-Frowen committed May 5, 2023
1 parent 25058d9 commit 7333749
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void Connect(string address = null, ushort? port = null)
InitializeAuthEvents();

// invoke started event after everything is set up, but before peer has connected
ObjectManager.ClientStarted(this);
if (ObjectManager != null)
ObjectManager.ClientStarted(this);
_started.Invoke();
}

Expand Down Expand Up @@ -226,7 +227,8 @@ internal void ConnectHost(NetworkServer server, IDataHandler serverDataHandler)
RegisterHostHandlers();
InitializeAuthEvents();
// invoke started event after everything is set up, but before peer has connected
ObjectManager.ClientStarted(this);
if (ObjectManager != null)
ObjectManager.ClientStarted(this);
_started.Invoke();

// we need add server connection to server's dictionary first
Expand Down
3 changes: 2 additions & 1 deletion Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public void StartServer(NetworkClient localClient = null)
Active = true;
// make sure to call ServerObjectManager start before started event
// this is too stop any race conditions where other scripts add their started event before SOM is setup
ObjectManager?.ServerStarted(this);
if (ObjectManager != null)
ObjectManager.ServerStarted(this);
_started?.Invoke();

if (LocalClient != null)
Expand Down

0 comments on commit 7333749

Please sign in to comment.