Skip to content

Commit

Permalink
fix: #609 by spawning observers in NetworkServer.AddPlayerForConnecti…
Browse files Browse the repository at this point in the history
…on after setting the controller. There is no point in trying to spawn with a null controller in SetReady, because by definition no one can observer something that is null. (#623)
  • Loading branch information
miwarnec committed Mar 22, 2019
1 parent b7e977a commit 5c00577
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
6 changes: 1 addition & 5 deletions Assets/Mirror/Components/NetworkProximityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ public override bool OnCheckObserver(NetworkConnection newObserver)
if (forceHidden)
return false;

if (newObserver.playerController != null)
{
return Vector3.Distance(newObserver.playerController.transform.position, transform.position) < visRange;
}
return false;
return Vector3.Distance(newObserver.playerController.transform.position, transform.position) < visRange;
}

public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
Expand Down
21 changes: 5 additions & 16 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla
// set ready if not set yet
SetClientReady(conn);

// add connection to observers AFTER the playerController was set.
// by definition, there is nothing to observe if there is no player
// controller.
SpawnObserversForConnection(conn);

if (SetupLocalPlayerForConnection(conn, identity))
{
return true;
Expand Down Expand Up @@ -805,24 +810,8 @@ public static void SetClientReady(NetworkConnection conn)
{
if (LogFilter.Debug) Debug.Log("SetClientReadyInternal for conn:" + conn.connectionId);

// do nothing if ready was set before
if (conn.isReady)
{
if (LogFilter.Debug) Debug.Log("SetClientReady conn " + conn.connectionId + " already ready");
return;
}

// set ready
conn.isReady = true;

if (conn.playerController == null)
{
// this is now allowed
if (LogFilter.Debug) Debug.LogWarning("Ready with no player object");
}

// spawn observers for this connection
SpawnObserversForConnection(conn);
}

internal static void ShowForConnection(NetworkIdentity identity, NetworkConnection conn)
Expand Down

0 comments on commit 5c00577

Please sign in to comment.