how to return the Animator from child when requested on a parent-gameobject?

Hi,

i have a gameobject that needs to act like it has an animator. --GetComponent();
In fact the child of that gameobject has the animator.
I want to return the Animator of the child when GetComponent(); is called on the parent.

I m an absolute csharp noob. could someone give me a code sample on how to usually do this?

why? - i 'm using two assets. one requires the animator to be in the child. one requires the animator to be in the actual gameobject. :slight_smile: - need to use both assets

best

Iโ€™d just create an Animator variable in the parent script that you assign in the inspector.

You can also use GetComponentInChildren.

Animator anim = GetComponent<Animator>();
if(anim == null) anim = transform.GetChild(0).GetComponent<Animator>();

thx guys.I was more thinking about if it is possible without changing something within the code of the plugins.

i ll definetly go with

  • if(anim == null) anim = transform.GetChild(0).GetComponent();

if there is no other way then altering the code in the plugin

No, I canโ€™t think of a way this would be possible.

k thx. i ll just change the plugin after every update

best