Skip to content

Commit a1fac91

Browse files
committed
chore: optimization
1 parent 6b8f88b commit a1fac91

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ internal bool HasParentNetworkObject(Transform transform)
359359
/// <summary>
360360
/// Gets the NetworkManager that owns this NetworkObject instance
361361
/// </summary>
362-
public NetworkManager NetworkManager => NetworkManagerOwner ? NetworkManagerOwner : NetworkManager.Singleton;
362+
// TODO use the correct one, here are we sure it is spawned? if it is, use NetworkManager
363+
public NetworkManager NetworkManager = NetworkManager.Singleton;
363364

364365
/// <summary>
365366
/// Useful to know if we should or should not send a message
@@ -1114,8 +1115,11 @@ public bool HasOwnershipStatus(OwnershipStatus status)
11141115
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11151116
private bool InternalHasAuthority()
11161117
{
1117-
var networkManager = NetworkManager;
1118-
return networkManager.DistributedAuthorityMode ? OwnerClientId == networkManager.LocalClientId : networkManager.IsServer;
1118+
if (!IsSpawned)
1119+
{
1120+
return false;
1121+
}
1122+
return NetworkManagerOwner.DistributedAuthorityMode ? OwnerClientId == NetworkManagerOwner.LocalClientId : NetworkManagerOwner.IsServer;
11191123
}
11201124

11211125
/// <summary>
@@ -1166,17 +1170,17 @@ private bool InternalHasAuthority()
11661170
/// <summary>
11671171
/// Gets if the object is the personal clients player object
11681172
/// </summary>
1169-
public bool IsLocalPlayer => NetworkManager != null && IsPlayerObject && OwnerClientId == NetworkManager.LocalClientId;
1173+
public bool IsLocalPlayer => IsPlayerObject && OwnerClientId == NetworkManager.LocalClientId;
11701174

11711175
/// <summary>
11721176
/// Gets if the object is owned by the local player or if the object is the local player object
11731177
/// </summary>
1174-
public bool IsOwner => NetworkManager != null && OwnerClientId == NetworkManager.LocalClientId;
1178+
public bool IsOwner => OwnerClientId == NetworkManager.LocalClientId;
11751179

11761180
/// <summary>
11771181
/// Gets Whether or not the object is owned by anyone
11781182
/// </summary>
1179-
public bool IsOwnedByServer => NetworkManager != null && OwnerClientId == NetworkManager.ServerClientId;
1183+
public bool IsOwnedByServer => OwnerClientId == NetworkManager.ServerClientId;
11801184

11811185
/// <summary>
11821186
/// Gets if the object has yet been spawned across the network

0 commit comments

Comments
 (0)