Skip to content

Commit 0e84dcd

Browse files
fix: updating testproject NetworkAnimator test (#2075)
* fix This resolves the issue with NetworkAnimator not de-registering itself from OnClientConnected. This resolves some issues with the manual NetworkAnimator test. * update MTT-4080 (this branch includes fixes for the OnClientConnectedCallback issue) Renamed NetworkAnimatorEnhancement scene to NetworkAnimatorServerOwnerTest. Adding the manual NetworkAnimatorServerOwnerTest scene to the scenes in build list. * style fixing whitespace issue. * update Fixing how AnimatedCubeController determines the type of NetworkAnimator and whether it is server or owner authoritative. * update Simplifying the conditional check requirements down to IsSpawned and IsOwner for the AnimationUserInput component since the only input checked should always be by the owner. * update removing an artifact from cherry picking a previous branch's work that included the manual test fixes. * style removing unused property.
1 parent 6d37247 commit 0e84dcd

File tree

8 files changed

+18
-21
lines changed

8 files changed

+18
-21
lines changed

testproject/Assets/References/Scene/NetworkAnimatorEnhancements.asset renamed to testproject/Assets/References/Scene/NetworkAnimatorServerOwnerTest.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MonoBehaviour:
1010
m_Enabled: 1
1111
m_EditorHideFlags: 0
1212
m_Script: {fileID: 11500000, guid: 39a16938ffb5cd846a9f6df7a686a9c4, type: 3}
13-
m_Name: NetworkAnimatorEnhancements
13+
m_Name: NetworkAnimatorServerOwnerTest
1414
m_EditorClassIdentifier:
1515
SceneToReference: {fileID: 102900000, guid: f88da8bb8d07e11418eaad6524d5cc12, type: 3}
1616
m_IncludedScenes: []
File renamed without changes.

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimatedCubeController.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using Unity.Netcode;
34
using Unity.Netcode.Components;
@@ -14,23 +15,17 @@ public class AnimatedCubeController : NetworkBehaviour
1415
private NetworkAnimator m_NetworkAnimator;
1516
private bool m_IsServerAuthoritative = true;
1617

17-
private void Awake()
18+
private void DetermineNetworkAnimatorComponentType()
1819
{
19-
m_Animator = GetComponent<Animator>();
2020
m_NetworkAnimator = GetComponent<NetworkAnimator>();
21-
if (m_NetworkAnimator == null)
21+
if (m_NetworkAnimator != null)
2222
{
23-
m_NetworkAnimator = GetComponent<OwnerNetworkAnimator>();
24-
if (m_NetworkAnimator != null)
25-
{
26-
m_IsServerAuthoritative = false;
27-
}
28-
else
29-
{
30-
throw new System.Exception($"{nameof(AnimatedCubeController)} requires that it is paired with either a {nameof(NetworkAnimator)} or {nameof(OwnerNetworkAnimator)}. Neither of the two components were found!");
31-
}
23+
m_IsServerAuthoritative = m_NetworkAnimator.GetType() != typeof(OwnerNetworkAnimator);
24+
}
25+
else
26+
{
27+
throw new Exception($"{nameof(AnimatedCubeController)} requires that it is paired with either a {nameof(NetworkAnimator)} or {nameof(OwnerNetworkAnimator)}. Neither of the two components were found!");
3228
}
33-
m_Rotate = m_Animator.GetBool("Rotate");
3429
}
3530

3631
public override void OnNetworkSpawn()
@@ -39,6 +34,9 @@ public override void OnNetworkSpawn()
3934
{
4035
enabled = false;
4136
}
37+
m_Animator = GetComponent<Animator>();
38+
DetermineNetworkAnimatorComponentType();
39+
m_Rotate = m_Animator.GetBool("Rotate");
4240
}
4341

4442
private bool HasAuthority()

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimationUserInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private void Start()
1717
// Update is called once per frame
1818
private void LateUpdate()
1919
{
20-
if (!IsSpawned || !IsOwner && !IsServer)
20+
if (!IsSpawned || !IsOwner)
2121
{
2222
return;
2323
}
File renamed without changes.
File renamed without changes.

testproject/Assets/Tests/Manual/NetworkAnimatorTests/NetworkAnimatorTestPrefab.prefab

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ GameObject:
287287
- component: {fileID: 3078684837582866037}
288288
- component: {fileID: 3078684837575715027}
289289
- component: {fileID: 5295167409644547614}
290-
- component: {fileID: 1923420540885290134}
290+
- component: {fileID: 3632991713004262889}
291291
m_Layer: 0
292292
m_Name: NetworkAnimatedCube-Owner
293293
m_TagString: Untagged
@@ -344,7 +344,7 @@ MonoBehaviour:
344344
m_Name:
345345
m_EditorClassIdentifier:
346346
TestIterations: 20
347-
--- !u!114 &1923420540885290134
347+
--- !u!114 &3632991713004262889
348348
MonoBehaviour:
349349
m_ObjectHideFlags: 0
350350
m_CorrespondingSourceObject: {fileID: 0}
@@ -353,11 +353,10 @@ MonoBehaviour:
353353
m_GameObject: {fileID: 3078684837583100501}
354354
m_Enabled: 1
355355
m_EditorHideFlags: 0
356-
m_Script: {fileID: 11500000, guid: e8d0727d5ae3244e3b569694d3912374, type: 3}
356+
m_Script: {fileID: 11500000, guid: f6a3556fb5f3bee4e8a0fb88acff87ff, type: 3}
357357
m_Name:
358358
m_EditorClassIdentifier:
359359
m_Animator: {fileID: 3078684837575715027}
360-
m_IsServerAuthoritative: 0
361360
--- !u!1 &3214090169133903718
362361
GameObject:
363362
m_ObjectHideFlags: 0
@@ -649,7 +648,6 @@ MonoBehaviour:
649648
m_Name:
650649
m_EditorClassIdentifier:
651650
m_Animator: {fileID: 6047057957339659638}
652-
m_IsServerAuthoritative: 1
653651
--- !u!1 &4033769488171516769
654652
GameObject:
655653
m_ObjectHideFlags: 0

testproject/ProjectSettings/EditorBuildSettings.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ EditorBuildSettings:
104104
- enabled: 1
105105
path: Assets/Tests/Manual/InSceneObjectParentingTests/InSceneNetworkObjectToLoad.unity
106106
guid: f06a8525a4b5200459f62905c29ce09e
107-
path: Assets/Tests/Manual/NetworkAnimatorTests/NetworkAnimatorEnhancement.unity
107+
- enabled: 1
108+
path: Assets/Tests/Manual/NetworkAnimatorTests/NetworkAnimatorServerOwnerTest.unity
108109
guid: f88da8bb8d07e11418eaad6524d5cc12
109110
m_configObjects:
110111
com.unity.addressableassets: {fileID: 11400000, guid: 5a3d5c53c25349c48912726ae850f3b0,

0 commit comments

Comments
 (0)