Forum rules - please read before posting.

Accessing the Animator(optional) in C# (solved)

edited November 2022 in Technical Q&A

Hi,
I instantiate a 3d character prefab through resource.load as a child to an empty game object (which has the npc script on it).
The reason being, when using CS or Triggers, AC needs a character to move to a marker for instance.

My issue is that the animations are not playing since the animator is on the empty game object.

Is there a way I can set the Animator or the Animator(optional) of the empty gameobject with the values of the child (3d character with the proper animation and avatar)?
Thank you.

Comments

  • edited November 2022

    I'm afraid I'm not following the reasoning behind it - and the NPC script should typically always be on the root object - but you can set the Animator field to a custom Animator component with this code:

    GetComponent<NPC> ().customAnimator = myAnimator;
    GetComponent<NPC> ().ResetAnimator ();
    
  • Thank you so much, you solved my problem in a few seconds.
    The reasoning is to have dynamic NPCs, with the same triggers/cs but different models.
    Thank you again, you're a life saver

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.