-
Notifications
You must be signed in to change notification settings - Fork 459
feat: NetworkAnimator and ClientNetworkAnimator #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- extracted the abstract base-class NetworkAnimator - ClientNetworkAnimator lives in Samples folder and is overriding NetworkAnimator to show client-authority - ServerNetworkAnimator lives in Components and is server-controlled. - updated the test scene to use two versions of the components - optimized unnecessary LINQ usage that caused GC pressure + caching the values to avoid invoking LINQ repeatedly - added capability for NetworkAnimator to be late-initialized by means of TryInitialize(Animator animator) method - it would allow to choose the Mecanim Animator component to sync later than on object spawn.
com.unity.netcode.gameobjects/Components/ServerNetworkAnimator.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Samples/ClientNetworkAnimator/Scripts/ClientNetworkAnimator.cs
Outdated
Show resolved
Hide resolved
/// </summary> | ||
[AddComponentMenu("Netcode/" + nameof(NetworkAnimator))] | ||
public class NetworkAnimator : NetworkBehaviour | ||
public abstract class NetworkAnimator : NetworkBehaviour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add automated tests for NetworkAnimator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sam and I had a conversation - he's fine with keeping the manual test for now, provided we add an automated soon.
…ity-Technologies/com.unity.netcode.gameobjects into pdeschain/networkanimator-refactoring
…n IsHost and dealing with ClientNetworkAnimator
…ameters are applied to the animator
…ity-Technologies/com.unity.netcode.gameobjects into pdeschain/networkanimator-refactoring
…code.gameobjects into pdeschain/networkanimator-refactoring # Conflicts: # com.unity.netcode.gameobjects/Components/NetworkAnimator.cs
/// This property tells us if the changes made to the Mecanim Animator will be synced to other peers or not. | ||
/// If not - then whatever local changes are done to the Mecanim Animator - they'll get overriden. | ||
/// </summary> | ||
public virtual bool WillCommitChanges => IsServer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we use Will
here compared to CanCommit
of the NetworkTransform. I think it would be nice if we could have a consistent API here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind changing it to CanCommit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanCommitToAnimator - to match the pattern from NetworkTransform
} | ||
} | ||
|
||
private ulong[] GetTargetClientIds(ulong originClientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether I fully grasp why we are doing this here and need this sort of caching? Don't we just send the update to every client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there has to be a way to do this in a more simple way. I mean sending RPCs. I saw a similar function for the server above as well. It's a lot of boilerplate just to send an RPC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're sending messages to every client except:
- the origin client
- and the server client (because we're sending this RPC from the server)
Prior version of this code relied on LINQ all the time to do this selection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure if we need to filter things out like that, but I would think that it conserves bandwidth to not send data to the peers who already have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I think for now this is fine. I hope we can get back at a later point in time and figure out whether there is a way to provide a simple pattern for something like a EveryoneExceptSelf
RPC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdeschain your comment "We're sending"...must include that in the source please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again, since NetworkAnimator should have just the server NA elements, this shouldn't be necessary here, only in CNA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, more like NetworkTransform, I'd prefer were your CNA just ignores what comes its way. After all, it should have its own local state, and it knows that it's its owner, so it can just skip that and avoid all this bookkeeping, no? Maybe I'm missing something.
…transform-teleport * sam/feature/client-network-transform: fixing issue with tests where we had tickrate set to 0. Removed singleton reference for this, since multiinstance tests don't like them :( delegate to allow server to override client changes work on setDelta feat: NetworkAnimator and ClientNetworkAnimator (#1191) # Conflicts: # com.unity.netcode.gameobjects/Components/NetworkTransform.cs
This reverts commit e47b73f.
} | ||
} | ||
|
||
private void SerializeBoolParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again unfortunately not a way to combine these mostly replicated functions
.Where(c => c.ClientId != NetworkManager.ServerClientId) | ||
.Select(c => c.ClientId) | ||
.ToArray() | ||
TargetClientIds = ServerToClientMessagingTargetClientIds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the intention with the client / server separation was to have the library be purely server authoritative; but to enable users that might want a ClientNetworkTransform or ClientNetworkAnimator in this case we have those implementations in Samples, just as you have done. Thing is, this NetworkAnimator itself is has the client auth code in it (line 627), and then we are just activating that code with the ClientNetworkAnimator "CanCommitToAnimator" toggle. It would be more aligned with what we're trying to do if instead we could do something like override SendAllParamsAndState in the CNA sample. It probably seems like splitting hairs, but I'd like to go more that direction
} | ||
} | ||
|
||
private ulong[] GetTargetClientIds(ulong originClientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdeschain your comment "We're sending"...must include that in the source please
} | ||
} | ||
|
||
private ulong[] GetTargetClientIds(ulong originClientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again, since NetworkAnimator should have just the server NA elements, this shouldn't be necessary here, only in CNA
} | ||
} | ||
|
||
private ulong[] GetTargetClientIds(ulong originClientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, more like NetworkTransform, I'd prefer were your CNA just ignores what comes its way. After all, it should have its own local state, and it knows that it's its owner, so it can just skip that and avoid all this bookkeeping, no? Maybe I'm missing something.
* Split NetworkAnimator into Client and Server auth versions - extracted the abstract base-class NetworkAnimator - ClientNetworkAnimator lives in Samples folder and is overriding NetworkAnimator to show client-authority - ServerNetworkAnimator lives in Components and is server-controlled. - updated the test scene to use two versions of the components - optimized unnecessary LINQ usage that caused GC pressure + caching the values to avoid invoking LINQ repeatedly - added capability for NetworkAnimator to be late-initialized by means of TryInitialize(Animator animator) method - it would allow to choose the Mecanim Animator component to sync later than on object spawn. * This is a blank commit * removed servernetworkanimator * optimization pass * # * fixed NetowrkAnimator applying animatorstate to itself twice when when IsHost and dealing with ClientNetworkAnimator * reverted a logic change in the order in which the synced animator parameters are applied to the animator * standards.py fix * Serializer api changed - updated the code accordingly * Jeff's comments * Luke's comments 1 * yamato standards
) * Split NetworkAnimator into Client and Server auth versions - extracted the abstract base-class NetworkAnimator - ClientNetworkAnimator lives in Samples folder and is overriding NetworkAnimator to show client-authority - ServerNetworkAnimator lives in Components and is server-controlled. - updated the test scene to use two versions of the components - optimized unnecessary LINQ usage that caused GC pressure + caching the values to avoid invoking LINQ repeatedly - added capability for NetworkAnimator to be late-initialized by means of TryInitialize(Animator animator) method - it would allow to choose the Mecanim Animator component to sync later than on object spawn. * This is a blank commit * removed servernetworkanimator * optimization pass * # * fixed NetowrkAnimator applying animatorstate to itself twice when when IsHost and dealing with ClientNetworkAnimator * reverted a logic change in the order in which the synced animator parameters are applied to the animator * standards.py fix * Serializer api changed - updated the code accordingly * Jeff's comments * Luke's comments 1 * yamato standards
…logies#1203) Reverts the introduction of ClientNetworkAnimator and modifications to NetworkAnimator types refs: e47b73f
PR exposes new API of the NetworkAnimator class family:
public abstract bool WillCommitChanges {get;}
public bool TryInitialize(Animator animator)