Skip to content

Commit b37d121

Browse files
fix: NetworkAnimator does not allow disabling or enabling parameters for synch (#3586)
* update Provide users with a way to disable updating changes to specific parameters. * update Don't include excluded parameters during initial synchronization. * update Adding the ability to select server or owner authority mode via the inspector view. * update - wip Work in progress. * update Test project manual tests for animation (of which some are used for integration testing). * update Finalizing editor inspector view UI for excluding animator properties. Added some additional logic to NetworkAnimator. Added first test that verifies excluding parameters works. * update Renamed the new method `ToggleParameterSync` to `EnableParameterSynchronization`. Added overridden version of `EnableParameterSynchronization` that accepts a string for the name and changed the original method to accept the hash value of the parameter name. Did some minor clean up in the `NetworkAnimatorStateChangeHandler.NetworkUpdate` method. Added some additional comments in various places. * update Reverted the change in HiddenScriptEditor. Moved away from a NetworkAnimator custom editor to a custom property drawer to handle displaying the Animator parameters to be synchronized. Handling the population of parameters and populating the NetworkAnimator.AnimatorParameterEntries during OnValidate. Had to re-apply unchecking the excluded parameter in some prefabs for testing purposes. * update Renaming NetworkAnimatorParameterEntryEditor to NetworkAnimatorParameterEntryDrawer since it is a property drawer. Excluding NetworkAnimatorParameterEntryDrawer when the animation package is not installed. * update Converting all legacy ClientRpc and ServerRpc usages over to the newer universal RPC format. Using a pre-allocated Persistent RpcTargetGroup as opposed to the List. When using `NetworkAnimator.SetTrigger` with a client-server network topology and it is the server or host invoking the method, then go ahead and set the trigger since it no longer sends itself an RPC/no longer invokes the InternalSetTrigger via RPC. * update Adding change log entries. * style adjusting typo * update Implementing suggested changes. * fix Fixing issue discovered by Noellie in the HasAuthority check. * update fixing change log * update Always assure owner authoritative mode when in distributed authority mode. * doc update Updating the NetworkAnimator documentation for this fix. * style - PVP PVP-124-2 Removing trailing spaces
1 parent 6436d68 commit b37d121

20 files changed

+1365
-247
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ Additional documentation and release notes are available at [Multiplayer Documen
1313
- It is now possible to control which port clients will bind to using the `UnityTransport.ConnectionData.ClientBindPort` field. If not set, clients will bind to an ephemeral port (same as before this change). (#3764)
1414
- Added a flag to override command-line arguments (port and ip) in `SetConnectionData`. (#3760)
1515
- Added a command-line singleton to parse environment command-line arguments. (#3760)
16-
16+
- Added `NetworkAnimator.AuthorityMode` which allows you to select whether the `NetworkAnimator` will use a server or owner authority model for state updates (like `NetworkTransform`). (#3586)
17+
- Added the ability to select which `Animator` parameters the authority `NetworkAnimator` instance should synchronize. This can be done via the inspector view interface or during runtime via `NetworkAnimator.EnableParameterSynchronization`. (#3586)
1718

1819
### Changed
1920

21+
- Changed NetworkAnimator to use the `RpcAttribute` along with the appropriate `SendTo` parameter. (#3586)
2022
- Improve performance of `NetworkTransformState`. (#3770)
2123

2224

@@ -32,6 +34,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
3234
- Fixed issue where invoking an RPC, on another `NetworkBehaviour` associated with the same `NetworkObject` that is ordered before the `NetworkBehaviour` invoking the RPC, during `OnNetworkSpawn` could throw an exception if scene management is disabled. (#3782)
3335
- Fixed issue where the `Axis to Synchronize` toggles didn't work with multi object editing in `NetworkTransform`. (#3781)
3436
- Fixed issue where using the dedicated server package would override all attempts to change the port by code. (#3760)
37+
- Fixed issue with authority animator instance sending itself RPCs. (#3586)
3538

3639
### Security
3740

com.unity.netcode.gameobjects/Documentation~/components/helper/networkanimator.md

Lines changed: 352 additions & 60 deletions
Large diffs are not rendered by default.
70.5 KB
Loading
15.3 KB
Loading
49 KB
Loading
3.82 MB
Loading
86.9 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
#if COM_UNITY_MODULES_ANIMATION
3+
using Unity.Netcode.Components;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace Unity.Netcode.Editor
8+
{
9+
[CustomPropertyDrawer(typeof(NetworkAnimator.AnimatorParametersListContainer))]
10+
internal class NetworkAnimatorParameterEntryDrawer : PropertyDrawer
11+
{
12+
// Draw the property inside the given rect
13+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
14+
{
15+
EditorGUI.BeginProperty(position, label, property);
16+
17+
// Draw the foldout for the list
18+
SerializedProperty items = property.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntries.ParameterEntries));
19+
position.height = EditorGUIUtility.singleLineHeight;
20+
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
21+
22+
if (property.isExpanded)
23+
{
24+
// Set the indention level down
25+
EditorGUI.indentLevel++;
26+
for (int i = 0; i < items.arraySize; i++)
27+
{
28+
position.y += EditorGUIUtility.singleLineHeight + 2;
29+
SerializedProperty element = items.GetArrayElementAtIndex(i);
30+
var nameField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.name));
31+
// Draw the foldout for the item
32+
element.isExpanded = EditorGUI.Foldout(position, element.isExpanded, nameField.stringValue);
33+
if (!element.isExpanded)
34+
{
35+
continue;
36+
}
37+
// Draw the contents of the item
38+
position.y += EditorGUIUtility.singleLineHeight + 2;
39+
// Set the indention level down
40+
EditorGUI.indentLevel++;
41+
// Calculate rects
42+
var nameHashRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
43+
position.y += EditorGUIUtility.singleLineHeight + 2;
44+
var paramRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
45+
position.y += EditorGUIUtility.singleLineHeight + 2;
46+
var syncRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
47+
48+
// Get the three properties we want to visualize in the inspector view
49+
var synchronizeField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.Synchronize));
50+
var nameHashField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.NameHash));
51+
var parameterTypeField = element.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntry.ParameterType));
52+
53+
// Draw the read only fields
54+
GUI.enabled = false;
55+
EditorGUI.PropertyField(nameHashRect, nameHashField);
56+
EditorGUI.PropertyField(paramRect, parameterTypeField);
57+
GUI.enabled = true;
58+
// Draw the read/write fields
59+
EditorGUI.PropertyField(syncRect, synchronizeField);
60+
// Set the indention level up
61+
EditorGUI.indentLevel--;
62+
}
63+
// Set the indention level up
64+
EditorGUI.indentLevel--;
65+
}
66+
EditorGUI.EndProperty();
67+
}
68+
69+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
70+
{
71+
var totalHeight = EditorGUIUtility.singleLineHeight;
72+
if (!property.isExpanded)
73+
{
74+
return totalHeight;
75+
}
76+
var singleLineWithSpace = EditorGUIUtility.singleLineHeight + 2;
77+
SerializedProperty items = property.FindPropertyRelative(nameof(NetworkAnimator.AnimatorParameterEntries.ParameterEntries));
78+
79+
totalHeight += singleLineWithSpace;
80+
for (int i = 0; i < items.arraySize; i++)
81+
{
82+
SerializedProperty element = items.GetArrayElementAtIndex(i);
83+
if (element.isExpanded)
84+
{
85+
totalHeight += (singleLineWithSpace * 4);
86+
}
87+
else
88+
{
89+
totalHeight += EditorGUIUtility.singleLineHeight;
90+
}
91+
}
92+
return totalHeight;
93+
}
94+
}
95+
}
96+
#endif

com.unity.netcode.gameobjects/Editor/NetworkAnimatorParameterEntryDrawer.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)