Skip to content

Commit 0bb1acf

Browse files
committed
Merge branch 'chore/simplify-accessors-misc' of https://github.com/Unity-Technologies/com.unity.netcode.gameobjects into chore/simplify-accessors-misc
# Conflicts: # com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
2 parents 39e476f + cf4783c commit 0bb1acf

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ internal void __endSendClientRpc(ref FastBufferWriter bufferWriter, uint rpcMeth
208208
{
209209
foreach (var targetClientId in clientRpcParams.Send.TargetClientIds)
210210
{
211-
if (targetClientId == NetworkManager.ServerClientId)
211+
if (targetClientId == networkManager.ServerClientId)
212212
{
213213
shouldInvokeLocally = true;
214214
continue;
@@ -225,7 +225,7 @@ internal void __endSendClientRpc(ref FastBufferWriter bufferWriter, uint rpcMeth
225225
{
226226
foreach (var targetClientId in clientRpcParams.Send.TargetClientIdsNativeArray)
227227
{
228-
if (targetClientId == NetworkManager.ServerClientId)
228+
if (targetClientId == networkManager.ServerClientId)
229229
{
230230
shouldInvokeLocally = true;
231231
continue;
@@ -353,7 +353,6 @@ internal FastBufferWriter __beginSendRpc(uint rpcMethodId, RpcParams rpcParams,
353353
internal void __endSendRpc(ref FastBufferWriter bufferWriter, uint rpcMethodId, RpcParams rpcParams, RpcAttribute.RpcAttributeParams attributeParams, SendTo defaultTarget, RpcDelivery rpcDelivery)
354354
#pragma warning restore IDE1006 // restore naming rule violation check
355355
{
356-
// Sould we create a local networkManager var to improve performance instead of using 2 times m_NetworkManager?
357356
var rpcMessage = new RpcMessage
358357
{
359358
Metadata = new RpcMetadata
@@ -579,7 +578,7 @@ public NetworkObject NetworkObject
579578
{
580579
get
581580
{
582-
if (m_NetworkObject)
581+
if (m_NetworkObject != null)
583582
{
584583
return m_NetworkObject;
585584
}
@@ -599,7 +598,7 @@ public NetworkObject NetworkObject
599598
// or NetworkBehaviour.IsSpawned (i.e. to early exit if not spawned) which, in turn, could generate several Warning messages
600599
// per spawned NetworkObject. Checking for ShutdownInProgress prevents these unnecessary LogWarning messages.
601600
// We must check IsSpawned, otherwise a warning will be logged under certain valid conditions (see OnDestroy)
602-
if (IsSpawned && !m_NetworkObject && (!m_NetworkManager || !m_NetworkManager.ShutdownInProgress))
601+
if (IsSpawned && !m_NetworkObject && (m_NetworkObject == null || !m_NetworkManager.ShutdownInProgress))
603602
{
604603
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
605604
{

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private void CheckForInScenePlaced()
390390
/// <param name="destroy">Defaults to true, determines whether the <see cref="NetworkObject"/> will be destroyed.</param>
391391
public void DeferDespawn(int tickOffset, bool destroy = true)
392392
{
393-
// Ensure we log the DAMode message first as locking ownership is not allowed if not in DAMode.
393+
// The DAMode message is logged first, as ownership locking isn’t allowed when not in DAMode, making it the most relevant message.
394394
if (!NetworkManager.DistributedAuthorityMode)
395395
{
396396
if (NetworkManager.LogLevel <= LogLevel.Error)
@@ -606,7 +606,7 @@ internal void RemoveOwnershipExtended(OwnershipStatusExtended extended)
606606
/// <returns>true or false depending upon lock operation's success</returns>
607607
public bool SetOwnershipLock(bool lockOwnership = true)
608608
{
609-
// Ensure we log the DAMode message first as locking ownership is not allowed if not in DAMode.
609+
// The DAMode message is logged first, as ownership locking isn’t allowed when not in DAMode, making it the most relevant message.
610610
if (!NetworkManager.DistributedAuthorityMode)
611611
{
612612
if (NetworkManager.LogLevel <= LogLevel.Error)
@@ -2230,7 +2230,6 @@ internal bool InternalTrySetParent(NetworkObject parent, bool worldPositionStays
22302230
}
22312231

22322232
m_CachedWorldPositionStays = worldPositionStays;
2233-
if (parent == null)
22342233
CurrentParent = parent;
22352234
transform.SetParent(CurrentParent?.transform, worldPositionStays);
22362235

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
526526
}
527527
else if (!isAuthorized)
528528
{
529-
throw new NotServerException("Only the server can change ownership");
529+
if (NetworkManager.LogLevel <= LogLevel.Error)
530+
{
531+
NetworkLog.LogError($"Only the server can change ownership! (ignoring)");
532+
return;
533+
}
530534
}
531535

532536
//Should this go at the beginning of the function?

0 commit comments

Comments
 (0)