Skip to content

Suggestion - remove [RequireComponent(typeof(Animator))] in NetworkAnimator #2112

Closed

Description

@Sirall

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

Activity

  1. added
    stat:awaiting-triageStatus - Awaiting triage from the Netcode team.
    type:featureNew feature, request or improvement
    on Aug 10, 2022
  2. NoelStephensUnity commented on Oct 4, 2022

    @NoelStephensUnity
    Member

    @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?

  3. yikfungtan99 commented on Aug 28, 2023

    @yikfungtan99

    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.

  4. NoelStephensUnity commented on Aug 29, 2023

    @NoelStephensUnity
    Member

    @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 NetworkAnimator configuration
    • Spawn the network prefab needed and parent that spawned NetworkObject under the player's NetworkObject using NetworkObject.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?

  5. yikfungtan99 commented on Aug 30, 2023

    @yikfungtan99

    Yea I am using the solution you mention right now

  6. NoelStephensUnity commented on Apr 5, 2024

    @NoelStephensUnity
    Member

    #2872 is the merging of a user submitted solution that removes this requirement.
    This will be in the next (v1.9.0) update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature, request or improvement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions