AnimancerUtilities.

FindRoot(GameObject) Method

Summary

[Editor-Only] Takes a `gameObject` and returns the root UnityEngine.Transform of the character it is part of.
Assembly
Animancer.dll
Namespace
Animancer
Containing Type
AnimancerUtilities

Syntax

public static Transform FindRoot(GameObject gameObject)

Examples

Simple Hierarchy

- Character - Rigidbody, etc.
    - Model - Animator, AnimancerComponent
    - States - Various components which reference the AnimationClips they will play
Passing the Model into this method will return the Character because it has the same number of Animator components in its children.

Shared Hierarchy

- Characters - Empty object used to group all characters
    - Character - Rigidbody, etc.
        - Model - Animator, AnimancerComponent
        - States - Various components which reference the AnimationClips they will play
    - Another Character
        - Model
        - States
  • Model has one Animator and no more in its children.
  • And Character has one Animator in its children (the same one).
  • But Characters has two Animators in its children (one on each character).
So it picks the Character as the root.

Complex Hierarchy

- Character - Rigidbody, etc.
    - Model - Animator, AnimancerComponent
    - States - Various components which reference the AnimationClips they will play
    - Another Model - Animator (maybe the character is holding a gun which has a reload animation)
In this case, the automatic system would see that the Character already has more child UnityEngine.Animators than the selected Model so it would only return the Model itself. This can be fixed by making any of the scripts on the Character implement Animancer.ICharacterRoot to tell the system which object you want it to use as the root.

Remarks

This method first searches all parents for a component implementing Animancer.ICharacterRoot. If it finds one, it returns the Animancer.ICharacterRoot.transform.

Otherwise, if the object is part of a prefab then it returns the root of that prefab instance.

Otherwise, it counts the number of Animators in the children of the `gameObject` then does the same for each parent. If it finds a parent with a different number of child Animators, it assumes that object is the parent of multiple characters and returns the previous parent as the root.

Parameters

Name Type Description
gameObject GameObject

Return Value

Type Description
Transform