Suggestion - remove [RequireComponent(typeof(Animator))] in NetworkAnimator
Is your feature request related to a problem? Please describe. NetworkAnimator require to be on the same game object as Animator, but it looks that by design it's not necceserly. The Animator component can and is attached manually. I prefer to remove this requirement because animator root and network game object root can be different.
Describe the solution you'd like Just remove [RequireComponent(typeof(Animator))] in NetworkAnimator.
Describe alternatives you've considered N/A
Additional context N/A
@Sirall It is valid to have a hierarchy like this:
- Root GameObject with NetworkObject component attached
- Child GameObject with Animator and NetworkAnimator components attached
With that said, could you further describe what kind of hierarchy you are trying to achieve that cannot be achieved with the above suggested hierarchy?
What if I have a player character with a child gameobject as the players visual and I dynamically spawn the visual gameObject with the network animator in it. If I make the child visual as a NetworkObject (which it does not required to be one) I get the error networkobject cannot spawn with a nested networkobject. If I move my network animator to the root of the player gameobject, it automatically create a undestroyable animator that does not contain the proper animation, which gets auto referenced. I did try just letting the autogenerated animator in the root be and refrence the child animator through script, that leads to the empty animator spitting out no controller error.
I feels like this is a mistake, somehow when I check the reference of the NetworkAnimator, it is the correct animator, but its complaining about the Animator (not the referenced but the one generated by the requiredcomponent) in the root having no controller.
@yikfungtan99
Most likely the issue is that NetworkAnimator requires pre-processing, it implements ISerializationCallbackReceiver, to occur when it is serialized (i.e. in the editor typically when entering play mode or making a build). This step is required as certain editor specific classes have the information needed to be able to synchronize animations properly (one example is AnimatorController).
The best way to handle this would be:
- Make individual network prefabs each with their own Animator and
NetworkAnimatorconfiguration - Spawn the network prefab needed and parent that spawned
NetworkObjectunder the player'sNetworkObjectusingNetworkObject.TrySetParent.
However, in order to give you any other possible solution I would need more details on your project's design that requires you to dynamically spawn a GameObject with NetworkAnimator. As an example, do you have dynamically generated animation information or do you have some form of character selection that includes animation information?
Yea I am using the solution you mention right now
#2872 is the merging of a user submitted solution that removes this requirement. This will be in the next (v1.9.0) update.