Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ private void DisplayNetworkManagerProperties()
}
}
var networkPrefabs = m_NetworkManager.NetworkConfig.MigrateOldNetworkPrefabsToNetworkPrefabsList();
#if UNITY_6000_2_OR_NEWER
string path = Path.Combine(directory, $"NetworkPrefabs-{m_NetworkManager.GetEntityId()}.asset");
#else
string path = Path.Combine(directory, $"NetworkPrefabs-{m_NetworkManager.GetInstanceID()}.asset");
#endif
Debug.Log("Saving migrated Network Prefabs List to " + path);
AssetDatabase.CreateAsset(networkPrefabs, path);
EditorUtility.SetDirty(m_NetworkManager);
Expand Down Expand Up @@ -390,7 +394,8 @@ public override void OnInspectorGUI()
#if !MULTIPLAYER_TOOLS
DrawInstallMultiplayerToolsTip();
#endif
void SetExpanded(bool expanded) { networkManager.NetworkManagerExpanded = expanded; };
void SetExpanded(bool expanded) { networkManager.NetworkManagerExpanded = expanded; }
;
DrawFoldOutGroup<NetworkManager>(networkManager.GetType(), DisplayNetworkManagerProperties, networkManager.NetworkManagerExpanded, SetExpanded);
DisplayCallToActionButtons();
base.OnInspectorGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public void RegisterHandler(IContactEventHandler contactEventHandler, bool regis
{
return;
}
#if UNITY_6000_2_OR_NEWER
var instanceId = rigidbody.GetEntityId();
#else
var instanceId = rigidbody.GetInstanceID();
#endif
if (register)
{
if (!m_RigidbodyMapping.ContainsKey(instanceId))
Expand Down
51 changes: 17 additions & 34 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,7 @@ public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true)
// DANGO-TODO: Do we want to worry about ownership permissions here?
// It wouldn't make sense to not allow parenting, but keeping this note here as a reminder.
var isAuthority = HasAuthority || (AllowOwnerToParent && IsOwner);
Debug.Log($"something is broken! isAuthority={isAuthority} | HasAuthority={HasAuthority} | (AllowOwnerToParent && IsOwner)={(AllowOwnerToParent && IsOwner)}");

// If we don't have authority and we are not shutting down, then don't allow any parenting.
// If we are shutting down and don't have authority then allow it.
Expand Down Expand Up @@ -2376,47 +2377,29 @@ private void OnTransformParentChanged()
m_CachedWorldPositionStays = true;
}

// If we are connected to a CMB service or we are running a mock CMB service then send to the "server" identifier
if (distributedAuthority || (!distributedAuthority && AllowOwnerToParent && IsOwner && !NetworkManager.IsServer))
// If we're not the server, we should tell the server about this parent change
if (!NetworkManager.IsServer)
{
if (!NetworkManager.DAHost)
// Don't send a message in DA mode if we're the only observers of this object (we're the only authority).
if (distributedAuthority && Observers.Count <= 1)
{
NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType<ParentSyncMessage>.DefaultDelivery, 0);
return;
}
else
{
foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds)
{
if (clientId == NetworkManager.ServerClientId)
{
continue;
}
NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType<ParentSyncMessage>.DefaultDelivery, clientId);
}
}

NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType<ParentSyncMessage>.DefaultDelivery, NetworkManager.ServerClientId);
return;
}
else

// Otherwise we are a Server (client-server or DAHost). Send to all observers
foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds)
{
// Otherwise we are running in client-server =or= this has to be a DAHost instance.
// Send to all connected clients.
unsafe
if (clientId == NetworkManager.ServerClientId)
{
var maxCount = NetworkManager.ConnectedClientsIds.Count;
ulong* clientIds = stackalloc ulong[maxCount];
int idx = 0;
foreach (var clientId in NetworkManager.ConnectionManager.ConnectedClientIds)
{
if (clientId == NetworkManager.ServerClientId)
{
continue;
}
if (Observers.Contains(clientId))
{
clientIds[idx++] = clientId;
}
}
NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType<ParentSyncMessage>.DefaultDelivery, clientIds, idx);
continue;
}
if (Observers.Contains(clientId))
{
NetworkManager.ConnectionManager.SendMessage(ref message, MessageDeliveryType<ParentSyncMessage>.DefaultDelivery, clientId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,11 @@ private void InitDriver()
out m_UnreliableFragmentedPipeline,
out m_UnreliableSequencedFragmentedPipeline,
out m_ReliableSequencedPipeline);

#if UNITY_6000_2_OR_NEWER
TransportInitialized?.Invoke(GetEntityId(), m_Driver);
#else
TransportInitialized?.Invoke(GetInstanceID(), m_Driver);
#endif
}

private void DisposeInternals()
Expand All @@ -446,7 +449,11 @@ private void DisposeInternals()

m_SendQueue.Clear();

#if UNITY_6000_2_OR_NEWER
TransportDisposed?.Invoke(GetEntityId());
#else
TransportDisposed?.Invoke(GetInstanceID());
#endif
}

/// <summary>
Expand Down Expand Up @@ -496,14 +503,11 @@ public NetworkSettings GetDefaultNetworkSettings()
// Latency, jitter and packet loss will be set by the network simulator in the tools
// package. We just need to initialize the settings since otherwise these features will
// not be enabled at all in the driver.
settings.WithSimulatorStageParameters(
// Assuming a maximum average latency of 50 ms, and that we're somehow able to flush
// an entire reliable window every tick, then at 60 ticks per second we need to be
// able to store 60 * 0.05 * 64 = 192 packets per connection in the simulator
// pipeline stage. Double that since we handle both directions and round it up, and
// that's how we get 400 here.
maxPacketCount: 400,
randomSeed: DebugSimulatorRandomSeed ?? (uint)System.Diagnostics.Stopwatch.GetTimestamp());
// Assuming a maximum average latency of 50 ms, and that we're somehow able to flush an entire reliable window every tick,
// then at 60 ticks per second we need to be able to store 60 * 0.05 * 64 = 192 packets per connection in the simulator
// pipeline stage. Double that since we handle both directions and round it up, and
// that's how we get 400 here.
settings.WithSimulatorStageParameters(maxPacketCount: 400, randomSeed: DebugSimulatorRandomSeed ?? (uint)System.Diagnostics.Stopwatch.GetTimestamp());
settings.WithNetworkSimulatorParameters();
#endif

Expand Down Expand Up @@ -1100,15 +1104,18 @@ private void ExtractNetworkMetrics()
{
if (m_NetworkManager.IsServer)
{
for (int i=0; i<m_NetworkManager.ConnectedClientsIds.Count; ++i)
for (int i = 0; i < m_NetworkManager.ConnectedClientsIds.Count; ++i)
{
var ngoConnectionId = m_NetworkManager.ConnectedClientsIds[i];
var ngoConnectionId = m_NetworkManager.ConnectedClientsIds[i];
if (ngoConnectionId == 0 && m_NetworkManager.IsHost)
{
continue;
}
var transportClientId = m_NetworkManager.ConnectionManager.ClientIdToTransportId(ngoConnectionId);
ExtractNetworkMetricsForClient(transportClientId);
var transportClientIdReturn = m_NetworkManager.ConnectionManager.ClientIdToTransportId(ngoConnectionId);
if (transportClientIdReturn.Item2)
{
ExtractNetworkMetricsForClient(transportClientIdReturn.Item1);
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ private bool TransformsMatch(StringBuilder errorLog)

foreach (var networkManager in m_NetworkManagers)
{
if (!networkManager.SpawnManager.SpawnedObjects.ContainsKey(m_AuthoritySeqControllerInstance.NetworkObjectId))
{
hasErrors = true;
continue;
}
var nonAuthorityInstance = networkManager.SpawnManager.SpawnedObjects[m_AuthoritySeqControllerInstance.NetworkObjectId].GetComponent<SpawnSequenceController>();
var nonAuthorityEulerRotation = nonAuthorityInstance.GetSpaceRelativeRotation().eulerAngles;

Expand Down Expand Up @@ -173,7 +178,7 @@ public IEnumerator OrderOfOperations()
var parent1 = m_AuthorityParentInstances[0];
var parent2 = m_AuthorityParentInstances[1];

ConfigureSequencesTest1(parent1);
ConfigureSequencesTest1_ClientServerOnly(parent1);
yield return RunTestSequences();

ConfigureSequencesTest2(parent1);
Expand Down Expand Up @@ -288,12 +293,19 @@ private IEnumerator __RunTestSequences(bool spawnWithObservers = true, bool spaw

#region Test Sequence Configurations
/// <summary>
/// Client server only - under da mode only the authority can parent
/// Test-1:
/// Authority-> Spawn, change ownership, (wait), parent
/// </summary>
private void ConfigureSequencesTest1(NetworkObject parent)
private void ConfigureSequencesTest1_ClientServerOnly(NetworkObject parent)
{
SpawnSequenceController.CurrentTest = "Test1";
SpawnSequenceController.CurrentTest = "Test1 (Client-Server Only)";
if (m_AuthorityNetworkManager.DistributedAuthorityMode)
{
SpawnSequenceController.ClientServerOnly = true;
return;
}

var changeOwnershipSequence = new ChangeOwnershipSequence()
{
Stage = SpawnSequence.SpawnStage.AfterSpawn,
Expand All @@ -305,6 +317,7 @@ private void ConfigureSequencesTest1(NetworkObject parent)
TimeDelayInMS = 200,
Stage = SpawnSequence.SpawnStage.AfterSpawn,
TargetParent = parent,
InvokeOnlyOnClientId = GetAuthorityNetworkManager().LocalClientId,
};

SpawnSequenceController.AddAction(changeOwnershipSequence);
Expand Down Expand Up @@ -855,6 +868,10 @@ protected override bool OnShouldInvoke(SpawnStage stage)
protected override void OnAction()
{
m_NetworkObject.ChangeOwnership(TargetOwnerClientId);
if (TargetOwnerClientId != m_NetworkObject.OwnerClientId)
{
Debug.LogError($"[{m_NetworkObject.name}] Failed to change ownership!");
}
base.OnAction();
}
}
Expand All @@ -866,7 +883,20 @@ internal class ParentSequence : SpawnSequence

protected override bool OnShouldInvoke(SpawnStage stage)
{
return base.OnShouldInvoke(stage) && (m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent));
// Don't invoke if the base says no
if (!base.OnShouldInvoke(stage))
{
return false;
}

// If sequence is configured to specifically invoke on this client
if (InvokeOnlyOnClientId.HasValue && m_NetworkObject.NetworkManager.LocalClientId == InvokeOnlyOnClientId.Value)
{
return true;
}

// Otherwise we should invoke if we have the authority to invoke
return m_NetworkObject.HasAuthority || (m_NetworkObject.IsOwner && m_NetworkObject.AllowOwnerToParent);
}

protected override void OnAction()
Expand Down
23 changes: 12 additions & 11 deletions testproject/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"disableProjectUpdate": false,
"dependencies": {
"com.unity.addressables": "2.2.2",
"com.unity.ai.navigation": "2.0.5",
"com.unity.collab-proxy": "2.6.0",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.mathematics": "1.3.2",
"com.unity.addressables": "2.7.4",
"com.unity.ai.navigation": "2.0.9",
"com.unity.collab-proxy": "2.9.3",
"com.unity.ide.rider": "3.0.38",
"com.unity.ide.visualstudio": "2.0.25",
"com.unity.mathematics": "1.3.3",
"com.unity.multiplayer.tools": "2.2.6",
"com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects",
"com.unity.package-validation-suite": "0.49.0-preview",
"com.unity.services.authentication": "3.4.0",
"com.unity.services.core": "1.14.0",
"com.unity.test-framework": "1.4.6",
"com.unity.test-framework.performance": "3.0.3",
"com.unity.timeline": "1.8.7",
"com.unity.services.authentication": "3.5.2",
"com.unity.services.multiplayer": "1.1.8",
"com.unity.test-framework": "1.6.0",
"com.unity.test-framework.performance": "3.1.0",
"com.unity.timeline": "1.8.9",
"com.unity.ugui": "2.0.0",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.ai": "1.0.0",
Expand Down
Loading