Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Animated children do not respect root motion when cloned.

Discussion in 'Prefabs' started by alexchesser, May 20, 2019.

  1. alexchesser


    Sep 15, 2017
    Hey Folks, Apologies if this is the wrong place to try and figure out some answers on this one.

    I've got a bit of a problem that I'm struggling to figure out.

    I have a Unity prefab where there are weapons are attached as children of the parent.

    The Legs in the stack have a root motion animation which carries the rest of the object forward, HOWEVER, when I instantiate a copy of this prefab onto the stage, the GUNS do not move with the rest of the body.

    If I manually drag a copy of this same prefab onto the stage before I launch the game all parts seem to move together as expected. It is only when I create the object and in code and add it to the gameplay area at runtime that this effect happens.

    I'm using 2019.1.3f1 if that helps.

    Has anyone seen this before? Have any tips or solutions?

    Notice the screenshot attached has two copied of the prefab showing side by side. the one labeled "sample text" is the raw prefab dragged directly onto the stage.

    The one labeled chesser_bot with the guns floating in air a few meters back is the one that was added directly to the stage.

    Screen Shot 2019-05-20 at 6.44.32 PM.png

    Screen Shot 2019-05-20 at 6.41.45 PM.png
  2. alexchesser


    Sep 15, 2017
    Update - OK - I've discovered that *IF* I do some trickery-pokery I can make the objects move together... but this feels really broken. I'd love some insight from an expert.

    I've added the following to my Player object and I update the transform for attached objects on every update.

    Code (CSharp):
    1. public class PlayerController : MonoBehaviour
    2. {
    4.     Transform Mount_Weapon_L;
    5.     Transform Mount_Weapon_R;
    6.     GameObject RW;
    7.     GameObject LW;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         // note that FindChildByRecursion is an extension method
    13.         // [URL][/URL]
    14.         Mount_Weapon_L = transform.FindChildByRecursion("Mount_Weapon_L");
    15.         Mount_Weapon_R = transform.FindChildByRecursion("Mount_Weapon_R");
    16.         GameObject W = Resources.Load("Weapons/Weapon_cannon_lvl1") as GameObject;
    17.         RW = Instantiate(W, Mount_Weapon_R, false);
    18.         LW = Instantiate(W, Mount_Weapon_L, false);
    19.     }
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    25.         RW.transform.position = Mount_Weapon_R.position;
    26.         LW.transform.position = Mount_Weapon_L.position;
    27.     }
    28. }
  3. Baste


    Jan 24, 2013
    I'd guess that this is a root motion bug, rather than a prefab bug.

    Try to deactivate root motion and move the things forward through a simple script, check if the weapons still move with the objects then.
  4. awesomedata


    Oct 8, 2014
    I'm almost certain I've seen a bugfix recently for this root motion thing in 2019, but I'm not sure the version.

    Might be good to look into. They've been doing a lot with animation lately, so it wouldn't surprise me if someone's unearthed a bug or two in the process.