Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d4e339d
fix: animator syncronization for >2 clients
Aug 10, 2022
6f97738
fix: remove redundant rpc call when host
SoprachevAK Aug 10, 2022
a6dbdd0
Refactor if condition
SoprachevAK Aug 15, 2022
d299570
Merge branch 'develop' into develop
Aug 15, 2022
12cfc9f
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 16, 2022
2d40fcd
test
NoelStephensUnity Aug 16, 2022
77681cf
update
NoelStephensUnity Aug 16, 2022
1ca68a0
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 16, 2022
f702e93
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 17, 2022
98d25aa
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 17, 2022
c98287d
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 17, 2022
06f6ee8
Merge develop into fix/client-authoritative-networkanimator
netcode-ci-service Aug 17, 2022
7afd726
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 18, 2022
15b9a60
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 18, 2022
0295ea0
fix
NoelStephensUnity Aug 18, 2022
253c9c3
style
NoelStephensUnity Aug 18, 2022
eb1bb26
update
NoelStephensUnity Aug 18, 2022
d27c4b0
fix
NoelStephensUnity Aug 18, 2022
1d1d291
update - wip
NoelStephensUnity Aug 19, 2022
977368e
update
NoelStephensUnity Aug 22, 2022
37bef8e
style
NoelStephensUnity Aug 22, 2022
fdb7a25
style
NoelStephensUnity Aug 22, 2022
ecf1939
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 23, 2022
48d1337
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Aug 24, 2022
770e6e8
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 13, 2022
37a5406
fix
NoelStephensUnity Sep 14, 2022
57dfe87
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 14, 2022
4827737
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 14, 2022
cf1b223
update and style
NoelStephensUnity Sep 14, 2022
ab28805
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 14, 2022
3a9b6ae
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 14, 2022
8cd7e7f
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 19, 2022
9d82547
test
NoelStephensUnity Sep 19, 2022
d21146e
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 23, 2022
0ed2621
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 28, 2022
8b86439
update
NoelStephensUnity Sep 28, 2022
dbf019a
udpate
NoelStephensUnity Sep 28, 2022
2f68b96
Merge branch 'develop' into fix/client-authoritative-networkanimator
NoelStephensUnity Sep 28, 2022
f7ee538
style
NoelStephensUnity Sep 28, 2022
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
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed the issue where running a server (i.e. not host) the second player would not receive updates (unless a third player joined). (#2127)
- Fixed issue where a client owner of a `NetworkVariable` with both owner read and write permissions would not update the server side when changed. (#2097)
- Fixed issue when attempting to spawn a parent `GameObject`, with `NetworkObject` component attached, that has one or more child `GameObject`s, that are inactive in the hierarchy, with `NetworkBehaviour` components it will no longer attempt to spawn the associated `NetworkBehaviour`(s) or invoke ownership changed notifications but will log a warning message. (#2096)
- Fixed an issue where destroying a NetworkBehaviour would not deregister it from the parent NetworkObject, leading to exceptions when the parent was later destroyed. (#2091)
Expand Down
6 changes: 3 additions & 3 deletions com.unity.netcode.gameobjects/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ private unsafe void SendParametersUpdateServerRpc(ParametersUpdateMessage parame
return;
}
UpdateParameters(parametersUpdate);
if (NetworkManager.ConnectedClientsIds.Count - 2 > 0)
if (NetworkManager.ConnectedClientsIds.Count > (IsHost ? 2 : 1))
{
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
Expand Down Expand Up @@ -812,7 +812,7 @@ private unsafe void SendAnimStateServerRpc(AnimationMessage animSnapshot, Server
return;
}
UpdateAnimationState(animSnapshot);
if (NetworkManager.ConnectedClientsIds.Count - 2 > 0)
if (NetworkManager.ConnectedClientsIds.Count > (IsHost ? 2 : 1))
{
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
Expand Down Expand Up @@ -857,7 +857,7 @@ private void SendAnimTriggerServerRpc(AnimationTriggerMessage animationTriggerMe
// trigger the animation locally on the server...
m_Animator.SetBool(animationTriggerMessage.Hash, animationTriggerMessage.IsTriggerSet);

if (NetworkManager.ConnectedClientsIds.Count - 2 > 0)
if (NetworkManager.ConnectedClientsIds.Count > (IsHost ? 2 : 1))
{
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ namespace TestProject.RuntimeTests
/// Possibly we could build this at runtime, but for now it uses the same animator controller as the manual
/// test does.
/// </summary>
[TestFixture(HostOrServer.Host)]
[TestFixture(HostOrServer.Server)]
public class NetworkAnimatorTests : NetcodeIntegrationTest
{
private const string k_AnimatorObjectName = "AnimatorObject";
private const string k_OwnerAnimatorObjectName = "OwnerAnimatorObject";

protected override int NumberOfClients => 1;
protected override int NumberOfClients => 2;
private GameObject m_AnimationTestPrefab => m_AnimatorObjectPrefab ? m_AnimatorObjectPrefab as GameObject : null;
private GameObject m_AnimationOwnerTestPrefab => m_OwnerAnimatorObjectPrefab ? m_OwnerAnimatorObjectPrefab as GameObject : null;

private AnimatorTestHelper.ParameterValues m_ParameterValues;
private Object m_AnimatorObjectPrefab;
private Object m_OwnerAnimatorObjectPrefab;

public NetworkAnimatorTests(HostOrServer hostOrServer)
{
m_UseHost = hostOrServer == HostOrServer.Host;
}

protected override void OnOneTimeSetup()
{
m_AnimatorObjectPrefab = Resources.Load(k_AnimatorObjectName);
Expand Down Expand Up @@ -352,14 +359,15 @@ public IEnumerator LateJoinTriggerSynchronizationTest([Values] OwnerShipMode own

yield return CreateAndStartNewClient();

Assert.IsTrue(m_ClientNetworkManagers.Length == 2, $"Newly created and connected client was not added to {nameof(m_ClientNetworkManagers)}!");
Assert.IsTrue(m_ClientNetworkManagers.Length == NumberOfClients + 1, $"Newly created and connected client was not added to {nameof(m_ClientNetworkManagers)}!");

// Wait for it to spawn client-side
yield return WaitForConditionOrTimeOut(WaitForClientsToInitialize);
AssertOnTimeout($"Timed out waiting for the late joining client-side instance of {GetNetworkAnimatorName(authoritativeMode)} to be spawned!");

// Make sure the AnimatorTestHelper client side instances (plus host) is the same as the TotalClients
Assert.True((AnimatorTestHelper.ClientSideInstances.Count + 1) == TotalClients);
// Make sure the AnimatorTestHelper client side instances is the same as the TotalClients
var calculatedClients = (AnimatorTestHelper.ClientSideInstances.Count + (m_UseHost ? 1 : 0));
Assert.True(calculatedClients == TotalClients, $"Number of client");

// Now check that the late joining client and all other clients are synchronized to the trigger
yield return WaitForConditionOrTimeOut(() => AllTriggersDetected(ownerShipMode));
Expand All @@ -378,7 +386,7 @@ public IEnumerator LateJoinTriggerSynchronizationTest([Values] OwnerShipMode own
yield return WaitForConditionOrTimeOut(() => ParameterValuesMatch(ownerShipMode, authoritativeMode, m_EnableVerboseDebug));
AssertOnTimeout($"Timed out waiting for the client-side parameters to match {m_ParameterValues.ValuesToString()}!");

var newlyJoinedClient = m_ClientNetworkManagers[1];
var newlyJoinedClient = m_ClientNetworkManagers[NumberOfClients];
yield return StopOneClient(newlyJoinedClient);
VerboseDebug($" ------------------ Late Join Trigger Test [{TriggerTest.Iteration}][{ownerShipMode}] Stopping ------------------ ");
}
Expand Down Expand Up @@ -433,16 +441,17 @@ public IEnumerator LateJoinSynchronizationTest([Values] OwnerShipMode ownerShipM
// Create and join a new client (late joining client)
yield return CreateAndStartNewClient();

Assert.IsTrue(m_ClientNetworkManagers.Length == 2, $"Newly created and connected client was not added to {nameof(m_ClientNetworkManagers)}!");
Assert.IsTrue(m_ClientNetworkManagers.Length == NumberOfClients + 1, $"Newly created and connected client was not added to {nameof(m_ClientNetworkManagers)}!");

// Wait for the client to have spawned and the spawned prefab to be instantiated
yield return WaitForConditionOrTimeOut(WaitForClientsToInitialize);
AssertOnTimeout($"Timed out waiting for the late joining client-side instance of {GetNetworkAnimatorName(authoritativeMode)} to be spawned!");

// Make sure the AnimatorTestHelper client side instances (plus host) is the same as the TotalClients
Assert.True((AnimatorTestHelper.ClientSideInstances.Count + 1) == TotalClients);
// Make sure the AnimatorTestHelper client side instances is the same as the TotalClients
var calculatedClients = (AnimatorTestHelper.ClientSideInstances.Count + (m_UseHost ? 1 : 0));
Assert.True(calculatedClients == TotalClients, $"Number of client");

var lateJoinObjectInstance = AnimatorTestHelper.ClientSideInstances[m_ClientNetworkManagers[1].LocalClientId];
var lateJoinObjectInstance = AnimatorTestHelper.ClientSideInstances[m_ClientNetworkManagers[NumberOfClients].LocalClientId];
yield return WaitForConditionOrTimeOut(() => Mathf.Approximately(lateJoinObjectInstance.transform.rotation.eulerAngles.y, 180.0f));
AssertOnTimeout($"[Late Join] Timed out waiting for cube to reach 180.0f!");

Expand Down Expand Up @@ -480,17 +489,17 @@ private void Server_OnClientConnectedCallback(ulong obj)
/// </summary>
private bool LateJoinClientSynchronized()
{
if (!StateSyncTest.StatesEntered.ContainsKey(m_ClientNetworkManagers[1].LocalClientId))
if (!StateSyncTest.StatesEntered.ContainsKey(m_ClientNetworkManagers[NumberOfClients].LocalClientId))
{
return false;
}

var serverStates = StateSyncTest.StatesEntered[m_ServerNetworkManager.LocalClientId];
var clientStates = StateSyncTest.StatesEntered[m_ClientNetworkManagers[1].LocalClientId];
var clientStates = StateSyncTest.StatesEntered[m_ClientNetworkManagers[NumberOfClients].LocalClientId];

if (serverStates.Count() != clientStates.Count())
{
VerboseDebug($"[Count][Server] {serverStates.Count} | [Client-{m_ClientNetworkManagers[1].LocalClientId}]{clientStates.Count}");
VerboseDebug($"[Count][Server] {serverStates.Count} | [Client-{m_ClientNetworkManagers[NumberOfClients].LocalClientId}]{clientStates.Count}");
return false;
}

Expand Down