Search Unity

Question Working on a shapeshift mechanic and can't get animator to work on more than one child.

Discussion in 'Animation' started by Tomajiro, Jan 23, 2022.

  1. Tomajiro

    Tomajiro

    Joined:
    Nov 30, 2021
    Posts:
    7
    This function uses a parent player rig to host input, movement, and rigidbody. It also host's the Shapeshift script, which is the script referred to in this post.

    Each child has an animator with a unique controller, character model, rig, and animations.

    I've tried a few different scripting methods but cannot get unity to use the Animator from the relevant child after each shapeshift. No matter what I try, it always uses the first active child's Animator on scene load. Then once I activate the shapeshift function, it will load the new child in it's idle state but will not register my inputs in the Animator.

    By looking at the animation blend tree during runtime, I can see my inputs registering on the first active child, but once I shapeshift, inputs no longer register on any child until I shapeshift back to the original child.

    Code (CSharp):
    1. [SerializeField] Animator[] animator;
    Don't know if I need to use SerializeField here or not. It doesn't have any effect either way at the moment.


    Code (CSharp):
    1. void Awake()
    2.         {
    3.             animator = GetComponentsInChildren<Animator>();
    4.         }
    Finds all child animator components. I have all child objects active on scene load so the array can find all of them.

    Code (CSharp):
    1. void Start()
    2.         {
    3.             personOne.SetActive(true);
    4.             personTwo.SetActive(false);
    5.  
    6.  
    7. void Update()
    8.         {
    9.            
    10.             if (Input.GetKeyDown(shapeshift))
    11.             {
    12.                 if (personOne.activeInHierarchy)
    13.                 {
    14.                     personTwo.SetActive(true);
    15.                     personOne.SetActive(false);
    16.                     animator[0].enabled = false;
    17.                     animator[1].enabled = true;
    18.                     return;
    I know this isn't the most economical code but for now its just a prototype. I will simplify it later. Any other scripting efforts have all led the same result. Any child except for the first one will not record inputs into the animation blend tree.


    Any help with this is greatly appreciated! Just need a nudge in the right direction. Thanks!
     
  2. unity_2cdeity

    unity_2cdeity

    Joined:
    Dec 19, 2020
    Posts:
    17
    If your going to do this, which I recommend to give up on disabling the entire object...

    The script I need to see would be the one referencing the animator.... You are undoubtedly missing the timing, when you disable one you need to resend the last command to the second when its enabled but I cant tell from this example. also the controller could be in the wrong state...