Skip to content

Commit

Permalink
fix: isLocalPlayer is true during OnStartClient for Player (#1255)
Browse files Browse the repository at this point in the history
related to #1250 but for client mode.

Before:

```
Void Awake() hasAuthority=False isClient=False isLocalPlayer=False
Void OnStartClient() hasAuthority=True isClient=True isLocalPlayer=False
Void OnStartAuthority() hasAuthority=True isClient=True isLocalPlayer=False
Void OnStartLocalPlayer() hasAuthority=True isClient=True isLocalPlayer=True
Void Start() hasAuthority=True isClient=True isLocalPlayer=True
```

After:
```
Void Awake() hasAuthority=False isClient=False isLocalPlayer=False
Void OnStartClient() hasAuthority=True isClient=True isLocalPlayer=True
Void OnStartAuthority() hasAuthority=True isClient=True isLocalPlayer=True
Void OnStartLocalPlayer() hasAuthority=True isClient=True isLocalPlayer=True
Void Start() hasAuthority=True isClient=True isLocalPlayer=True
```
  • Loading branch information
paulpach committed Nov 29, 2019
1 parent a2c273e commit fb26d00
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
identity.transform.localRotation = msg.rotation;
identity.transform.localScale = msg.scale;
identity.hasAuthority = msg.isOwner;
identity.netId = msg.netId;

if (msg.isLocalPlayer)
InternalAddPlayer(identity);

// deserialize components if any payload
// (Count is 0 if there were no components)
Expand All @@ -489,7 +493,6 @@ static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
identity.OnUpdateVars(payloadReader, true);
}

identity.netId = msg.netId;
NetworkIdentity.spawned[msg.netId] = identity;

// objects spawned as part of initial state are started on a second pass
Expand Down Expand Up @@ -719,8 +722,6 @@ static void CheckForLocalPlayer(NetworkIdentity identity)

// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO
identity.connectionToServer = readyConnection;
InternalAddPlayer(identity);

identity.SetLocalPlayer();

if (LogFilter.Debug) Debug.Log("ClientScene.OnOwnerMessage - player=" + identity.name);
Expand Down

0 comments on commit fb26d00

Please sign in to comment.