Skip to content

Conversation

pdeschain
Copy link
Contributor

@pdeschain pdeschain commented Sep 16, 2021

  • ClientNetworkAnimator lives in Samples folder and is overriding NetworkAnimator to implement client-authority
  • NetworkAnimator lives in Components and is server-authoritative.
  • updated the test scene to use the two versions of the components
  • LINQ usage has been completely removed and instead serialization is relying on reused buffers, and client lists are also cached (with rebuilds for everything when necessary - when a new client connects for instance)
  • 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.

PR exposes new API of the NetworkAnimator class family:
public abstract bool WillCommitChanges {get;}
public bool TryInitialize(Animator animator)

pdeschain and others added 3 commits September 15, 2021 21:07
 - 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.
/// </summary>
[AddComponentMenu("Netcode/" + nameof(NetworkAnimator))]
public class NetworkAnimator : NetworkBehaviour
public abstract class NetworkAnimator : NetworkBehaviour
Copy link
Contributor

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

Copy link
Contributor Author

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
@pdeschain pdeschain changed the title feat: ClientNetworkAnimator and ServerNetworkAnimator feat: NetworkAnimator and ClientNetworkAnimator Sep 17, 2021
…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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

@pdeschain pdeschain Sep 17, 2021

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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.

@pdeschain pdeschain merged commit e47b73f into develop Sep 17, 2021
@pdeschain pdeschain deleted the pdeschain/networkanimator-refactoring branch September 17, 2021 22:33
SamuelBellomo added a commit that referenced this pull request Sep 20, 2021
…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
JesseOlmer added a commit that referenced this pull request Sep 20, 2021
JesseOlmer pushed a commit that referenced this pull request Sep 20, 2021
Reverts the introduction of ClientNetworkAnimator and modifications to NetworkAnimator types

refs: e47b73f
SamuelBellomo added a commit that referenced this pull request Sep 20, 2021
…hnologies/com.unity.multiplayer.mlapi into sam/feature/transform-teleport

* 'sam/feature/transform-teleport' of github.com:Unity-Technologies/com.unity.multiplayer.mlapi:
  revert: ClientNetworkAnimator (#1191) (#1203)
}
}

private void SerializeBoolParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

mattwalsh-unity pushed a commit that referenced this pull request Sep 29, 2021
* 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
mollstam pushed a commit to Keepsake-Games/com.unity.netcode.gameobjects that referenced this pull request Feb 13, 2023
)

* 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
mollstam pushed a commit to Keepsake-Games/com.unity.netcode.gameobjects that referenced this pull request Feb 13, 2023
…logies#1203)

Reverts the introduction of ClientNetworkAnimator and modifications to NetworkAnimator types

refs: e47b73f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants