Search Unity

GameObject won't move when I attach an Animation Controller

Discussion in 'Editor & General Support' started by DanPHernbrott, Nov 14, 2013.

  1. DanPHernbrott

    DanPHernbrott

    Joined:
    May 16, 2013
    Posts:
    5
    When I attach an Animator component to my GameObject in order to animate it, it still moves. However, when I fill in the Controller with my Controller, my object will no longer move. I check, and my rigidbody2D definitely has Velocity, but it isn't moving.

    Any ideas as to why this might happen? I'm really at a loss, here.
     
  2. zerotri3

    zerotri3

    Joined:
    Nov 14, 2013
    Posts:
    5
    I'm getting a similar issue. The Animator component is causing the Rigidbody2D to not be able to move. Disabling the Animator component shows that the RigidBody2D component should be working otherwise. Collision handled by a Circle Collider 2D component. Willing to share project with Unity devs if requested.

    Note: Checking/Unchecking Animator parameters in the inspector while game is running causes physics to work as desired. Won't work as desired on startup however.
     
    Last edited: Nov 14, 2013
  3. DanPHernbrott

    DanPHernbrott

    Joined:
    May 16, 2013
    Posts:
    5
    Zerotri3, that sounds exactly like the issue I'm having. The weird thing is that I don't get this issue on my other objects, which seem to be set up in the exact same way, just this particular one.

    I've also disabled my CircleCollider2D, which does not seem to make a difference.

    Also of note that if I have an Animator component but do not apply an AnimationController to that Animator, it will still be able to move.
     
  4. DanPHernbrott

    DanPHernbrott

    Joined:
    May 16, 2013
    Posts:
    5
    I still haven't got a clue what the issue here is. Anyone?
     
  5. DanPHernbrott

    DanPHernbrott

    Joined:
    May 16, 2013
    Posts:
    5
    Sorry to keep bumping this, but I need to get this figured out. I started a blank unity project and made an animation. When I try to animate, I cannot alter the velocity of the rigidbody2D directly. This is a major problem. I need to be able to do this.
     
  6. zerotri3

    zerotri3

    Joined:
    Nov 14, 2013
    Posts:
    5
    Hey DanPHernbrott,

    After getting myself a little more acquainted with Unity I came back to try and determine the problem and it was rather embarrassing.
    It turns out that the animation I was applying to the object was actually modifying the transform of itself (though constantly back to the same value), rather than its child objects. This was causing any sort of forces applied to be ignored.

    Hope this helps,
    - Wynter Woods
     
  7. kuom

    kuom

    Joined:
    Nov 12, 2013
    Posts:
    3
    Ok I Figured out what is happening here. and how to Fix It! The problem is, when you are making an animation, if you move the root game object, rather than the actual sprite body parts inside the root object, then what ever parameter you changed gets locked.

    I did it for a Death Animation, where i grabbed the whole object hierarchy and moved it, and rotated it. So then the character couldn't move. I removed the position change on the root object in the Animation tab, then my character could move again. Yay! But they where walking backwards, only facing one way.

    this was because i had used the rotate in the animation, and was using transform.eulersAngles.y = 180; to flip the character back and forth. This is essentially the same as rotation, so it was locked as well.

    I removed all the animation keys that were changing the root object, and redid them on the body parts instead, and everything started working fine again. Thanks for the tip Wynter Woods, it was invaluable.
    hopefully, my reply can help someone as well
     
  8. Galactic_Muffin

    Galactic_Muffin

    Joined:
    Aug 14, 2013
    Posts:
    67
    This really sucks for people who build their entire animations with the unity animation engine itself. like for UI elements for example which pretty much NEED to be animated in unity if you are using Ugui. What you are saying is that these people have to redo their entire animations to fix this problem simply because their animator was automatically created on the wrong gameobject!?
     
    postador550 likes this.
  9. jankymidget

    jankymidget

    Joined:
    Jul 26, 2015
    Posts:
    7
    If you want to be able to change the that stuff, you'll have to create state machine behaviors, and script changes to velocity, angular rotation velocity, or cancel it whatever. Sometimes you have to turn apply root transform off in the script when you enter the state as it will completely nullify the animation or cause adverse effects.

    This is related to what kuom said as well.
     
  10. frickshow

    frickshow

    Joined:
    Jul 2, 2017
    Posts:
    2
    ohhh.... this is some old thread, probably no one will ever read this:
    ,But I fixed it, the point is that even if you have 100 animations, even if one of them is changing the position, you cant change it during gameplay, I have a death animation to raise the body, but it made all of the other animations not work, so removing it made everything better again.

    What you can do, is put your player in an empty game object, and change the position of the player with animation, but you will change the empty game object via code. this solved the issue
     
    bjudob, nstural, Zinru and 6 others like this.
  11. Datapax

    Datapax

    Joined:
    Sep 10, 2015
    Posts:
    4
    You need to Bake Into Pose the animations Root Transform Position. You can do this from the animation properties in the Inspector !!
    Inspector.png
     
    Last edited: Sep 15, 2017
    JPBA1984 likes this.
  12. DaniyarGilymov

    DaniyarGilymov

    Joined:
    Dec 26, 2017
    Posts:
    14
    Try to check "Apply Root Motion" in Animator properties
     
    SCW56, CeylanKiese, pren1 and 5 others like this.
  13. Lyme59

    Lyme59

    Joined:
    Aug 1, 2018
    Posts:
    1
    I experienced an issue like this when I tried to bring a prefab into a new scene. The player could move around in the original scene, but not when I tried to instantiate it in a new one.

    Following what was said above, I found an unwanted position keyframe in the Animation tab, which conflicted with the movement. I deleted it, and it worked as expected. I wouldn't have expected this because nothing was recording.
     
  14. adarshabn

    adarshabn

    Joined:
    Sep 7, 2018
    Posts:
    5
    STILL IM FINDING THIS ISSUE
     
  15. adarshabn

    adarshabn

    Joined:
    Sep 7, 2018
    Posts:
    5
    DID YOU FIND ANY ANSWER FOR THIS?
     
  16. Xonatron

    Xonatron

    Joined:
    Jan 14, 2013
    Posts:
    31
    Apply Root Motion worked for us.
     
  17. YeasinBeen

    YeasinBeen

    Joined:
    Jun 30, 2018
    Posts:
    1
    here i am giving you the solution , First make an empty game object , then add the player sprite as a child .
    Add all the rigidbodies and the Box colliders to the empty game object .Also add the player control script to the empty game object
    now run the animation , will solve your problem
     

    Attached Files:

    abisuhardino02 and TheDevilsIvy like this.
  18. nitinkipa098

    nitinkipa098

    Joined:
    Jan 21, 2019
    Posts:
    2
    SOLVED:
    I found that an animator component was attached to a child. I removed it because root already has the component. And it fixed the issue where when you change the child, the position of the root also changes, resulting in rigidbody not working (or technically fixed rigidbody position).
     
  19. MarshallVisions

    MarshallVisions

    Joined:
    Mar 30, 2019
    Posts:
    4
    Hi all. This was plauging me for months but I found the solution at least for me. I needed to add an additional layer / gameobject inbetween my root object and the root of the rig . Note* I'm not using Apply Root Motion on either

    so before I had:

    Player (root gameObject with most of the scripts)
    Armature (just an empty gameObject)
    { Pelvis
    Skinned Mesh as sibling of the Pelvis }


    After adding the extra layer and it all working:

    Player (root gameObject with most of the scripts)
    Dummy Root Object (another empty gameObject)
    Armature (just an empty gameObject)
    { Pelvis
    Skinned Mesh as sibling of the Pelvis }

    Hope this helps.. Such an easy fix but caused me months of frustration.
     
  20. Guersom92

    Guersom92

    Joined:
    Dec 2, 2019
    Posts:
    3
    I fix this problem by checking the box "Apply Root Motion " on the Animator component.
     
  21. vedantj1203

    vedantj1203

    Joined:
    Jul 6, 2019
    Posts:
    1
    Did you check "apply root motion"?
     
  22. SomethinStudios

    SomethinStudios

    Joined:
    Dec 3, 2017
    Posts:
    1
    I had this same issue along with everyone else. I tried multiple solutions, ranging from placing the animator on a child gameobject, placing the sprite renderer on a child gameobject, selecting apply root motion, deselecting apply root motion. Fiddling with animations, ensuring they aren't altering the primary gameobject position, but the bone's position. All kinds of stuff.

    What I believe worked for me, because I finally got it to work. I changed the component order of my primary player gameobject. And I deselected apply root motion, and Ensured I only had 1 animator on the primary gameobj, not 2 (one on primary and child gameobj).

    Component Order

    Gizmo (Primary Player GameObj)
    - Sprite Renderer
    - Rigidbody 2D
    - Capsule Collider
    - Player Movement Script
    - Animator
    - Sprite Skin

    GameObject Hierarchy, including child gameobjects

    Gizmo (Primary Player GameObj)
    - Body (Skeletal System)
    - GroundTransform (checks for ground)
    - WallTransform (checks for wall)
     
  23. laubus

    laubus

    Joined:
    Oct 12, 2020
    Posts:
    1
    i am happy this thread exists tho. how is one supposed to know that an animation can keep your gameObject from moving?! so thanks for sharing this, even though you thought know on is going to read this:D
     
  24. Zwinglijones

    Zwinglijones

    Joined:
    Jul 15, 2019
    Posts:
    1
    Thanks Man
     
  25. abisuhardino02

    abisuhardino02

    Joined:
    Jun 25, 2021
    Posts:
    1
    THIS WORK ON ME
     
  26. withoutdraw

    withoutdraw

    Joined:
    Dec 7, 2018
    Posts:
    1
    For me when i attach the animator controller into the player that was moving right it stop moving reading some comments made me realize i may changed the transform of the player in some animations i deleted the ones that i though they were suspicious and it worked.
     
  27. marcelo_augusto

    marcelo_augusto

    Joined:
    Nov 18, 2018
    Posts:
    12
    I am not sure I am facing the same issue. I have a parent object and two children. The parent has an Animator that moves the 2 children based on triggers (2D). I works fine. Now I need to move the same objects without animation in some cases. If I simply do it on script, nothing happens. If I disable the animator, the script can move them. Apply root motion does not change this behavior.
    Someone mentioned in this thread that it is not possible to do it and I am inclined to believe it.
     
  28. marcelo_augusto

    marcelo_augusto

    Joined:
    Nov 18, 2018
    Posts:
    12
  29. isuckatprogramming69

    isuckatprogramming69

    Joined:
    May 13, 2022
    Posts:
    1
    Still havent found a working answer :(
     
  30. maohk117

    maohk117

    Joined:
    Aug 6, 2022
    Posts:
    1
    This Actually Fix It!!! The easiest way, Thank you!
     
    SCW56 likes this.