Skip to content

Commit bdb6cd8

Browse files
author
mischa
committed
fix: #3528, #3529 NetworkBehaviour.authority now evaluates correctly in host mode too
1 parent 97dc02e commit bdb6cd8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Assets/Mirror/Core/NetworkBehaviour.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ public abstract class NetworkBehaviour : MonoBehaviour
7272
public bool hasAuthority => isOwned;
7373

7474
/// <summary>authority is true if we are allowed to modify this component's state. On server, it's true if SyncDirection is ServerToClient. On client, it's true if SyncDirection is ClientToServer and(!) if this object is owned by the client.</summary>
75-
// on the client: if owned and if clientAuthority sync direction
76-
// on the server: if serverAuthority sync direction
75+
// on the client: if Client->Server SyncDirection and owned
76+
// on the server: if Server->Client SyncDirection
77+
// on the host: if Server->Client SyncDirection (= server owns it), or if Client->Server and owned (=host client owns it)
78+
// in host mode: always true because either server or client always has authority, and host is both.
7779
//
7880
// for example, NetworkTransform:
7981
// client may modify position if ClientAuthority mode and owned
@@ -84,10 +86,20 @@ public abstract class NetworkBehaviour : MonoBehaviour
8486
//
8587
// also note that this is a per-NetworkBehaviour flag.
8688
// another component may not be client authoritative, etc.
87-
public bool authority =>
88-
isClient
89-
? syncDirection == SyncDirection.ClientToServer && isOwned
90-
: syncDirection == SyncDirection.ServerToClient;
89+
public bool authority
90+
{
91+
get
92+
{
93+
// host mode needs to be checked explicitly
94+
if (isClient && isServer) return syncDirection == SyncDirection.ServerToClient || isOwned;
95+
96+
// client-only
97+
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
98+
99+
// server-only
100+
return syncDirection == SyncDirection.ServerToClient;
101+
}
102+
}
91103

92104
/// <summary>The unique network Id of this object (unique at runtime).</summary>
93105
public uint netId => netIdentity.netId;

0 commit comments

Comments
 (0)