Skip to content

Commit 825eb36

Browse files
committed
Fix some tests
1 parent 7ccb06b commit 825eb36

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,14 +1171,7 @@ private bool InternalHasAuthority()
11711171
/// <summary>
11721172
/// Gets if the object is owned by the local player or if the object is the local player object
11731173
/// </summary>
1174-
public bool IsOwner
1175-
{
1176-
get
1177-
{
1178-
Debug.Log($"[Client-{NetworkManager.LocalClientId}][Object-{NetworkObjectId}] Owned by {OwnerClientId}");
1179-
return NetworkManager != null && OwnerClientId == NetworkManager.LocalClientId;
1180-
}
1181-
}
1174+
public bool IsOwner => NetworkManager != null && OwnerClientId == NetworkManager.LocalClientId;
11821175

11831176
/// <summary>
11841177
/// Gets Whether or not the object is owned by anyone
@@ -2224,12 +2217,12 @@ public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true)
22242217
// DANGO-TODO: Do we want to worry about ownership permissions here?
22252218
// It wouldn't make sense to not allow parenting, but keeping this note here as a reminder.
22262219
var isAuthority = HasAuthority || (AllowOwnerToParent && IsOwner);
2220+
Debug.Log($"something is broken! isAuthority={isAuthority} | HasAuthority={HasAuthority} | (AllowOwnerToParent && IsOwner)={(AllowOwnerToParent && IsOwner)}");
22272221

22282222
// If we don't have authority and we are not shutting down, then don't allow any parenting.
22292223
// If we are shutting down and don't have authority then allow it.
22302224
if (!isAuthority && !NetworkManager.ShutdownInProgress)
22312225
{
2232-
Debug.LogError("We don't have authority here");
22332226
return false;
22342227
}
22352228

@@ -2293,7 +2286,6 @@ private void OnTransformParentChanged()
22932286
// With distributed authority, we need to track "valid authoritative" parenting changes.
22942287
// So, either the authority or AuthorityAppliedParenting is considered a "valid parenting change".
22952288
isAuthority = HasAuthority || AuthorityAppliedParenting || (AllowOwnerToParent && IsOwner);
2296-
Debug.Log($"[Client-{NetworkManager.LocalClientId}][Object-{NetworkObjectId}] OnTransformParentChanged. HasAuthority={HasAuthority}, AuthorityAppliedParenting={AuthorityAppliedParenting}, AllowOwnerToParent && IsOwner={AllowOwnerToParent && IsOwner}");
22972289
var distributedAuthority = NetworkManager.DistributedAuthorityMode;
22982290

22992291
// If we do not have authority and we are spawned
@@ -2364,8 +2356,6 @@ private void OnTransformParentChanged()
23642356
var authorityApplied = AuthorityAppliedParenting;
23652357
ApplyNetworkParenting(removeParent);
23662358

2367-
2368-
23692359
var message = new ParentSyncMessage
23702360
{
23712361
NetworkObjectId = NetworkObjectId,

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformOrderOfOperations.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public IEnumerator OrderOfOperations()
178178
var parent1 = m_AuthorityParentInstances[0];
179179
var parent2 = m_AuthorityParentInstances[1];
180180

181-
ConfigureSequencesTest1(parent1);
181+
ConfigureSequencesTest1_ClientServerOnly(parent1);
182182
yield return RunTestSequences();
183183

184184
ConfigureSequencesTest2(parent1);
@@ -293,12 +293,19 @@ private IEnumerator __RunTestSequences(bool spawnWithObservers = true, bool spaw
293293

294294
#region Test Sequence Configurations
295295
/// <summary>
296+
/// Client server only - under da mode only the authority can parent
296297
/// Test-1:
297298
/// Authority-> Spawn, change ownership, (wait), parent
298299
/// </summary>
299-
private void ConfigureSequencesTest1(NetworkObject parent)
300+
private void ConfigureSequencesTest1_ClientServerOnly(NetworkObject parent)
300301
{
301-
SpawnSequenceController.CurrentTest = "Test1";
302+
SpawnSequenceController.CurrentTest = "Test1 (Client-Server Only)";
303+
if (m_AuthorityNetworkManager.DistributedAuthorityMode)
304+
{
305+
SpawnSequenceController.ClientServerOnly = true;
306+
return;
307+
}
308+
302309
var changeOwnershipSequence = new ChangeOwnershipSequence()
303310
{
304311
Stage = SpawnSequence.SpawnStage.AfterSpawn,
@@ -310,6 +317,7 @@ private void ConfigureSequencesTest1(NetworkObject parent)
310317
TimeDelayInMS = 200,
311318
Stage = SpawnSequence.SpawnStage.AfterSpawn,
312319
TargetParent = parent,
320+
InvokeOnlyOnClientId = GetAuthorityNetworkManager().LocalClientId,
313321
};
314322

315323
SpawnSequenceController.AddAction(changeOwnershipSequence);
@@ -860,6 +868,10 @@ protected override bool OnShouldInvoke(SpawnStage stage)
860868
protected override void OnAction()
861869
{
862870
m_NetworkObject.ChangeOwnership(TargetOwnerClientId);
871+
if (TargetOwnerClientId != m_NetworkObject.OwnerClientId)
872+
{
873+
Debug.LogError($"[{m_NetworkObject.name}] Failed to change ownership!");
874+
}
863875
base.OnAction();
864876
}
865877
}
@@ -871,7 +883,20 @@ internal class ParentSequence : SpawnSequence
871883

872884
protected override bool OnShouldInvoke(SpawnStage stage)
873885
{
874-
return base.OnShouldInvoke(stage) && (m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent));
886+
// Don't invoke if the base says no
887+
if (!base.OnShouldInvoke(stage))
888+
{
889+
return false;
890+
}
891+
892+
// If sequence is configured to specifically invoke on this client
893+
if (InvokeOnlyOnClientId.HasValue && m_NetworkObject.NetworkManager.LocalClientId == InvokeOnlyOnClientId.Value)
894+
{
895+
return true;
896+
}
897+
898+
// Otherwise we should invoke if we have the authority to invoke
899+
return m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent);
875900
}
876901

877902
protected override void OnAction()

0 commit comments

Comments
 (0)