Search Unity

Question Animation state locks rigidbody rotations/positions

Discussion in 'Animation' started by kzkkzm, Jan 6, 2023.

  1. kzkkzm

    kzkkzm

    Joined:
    Jan 6, 2023
    Posts:
    3
    I'm working on a 2D Unity project. In my scene, I have a centipede-alike GameObject, which is built via a hierarchy of rigidbodies and hinge joints. Without any Animator attached to it, the physics2D engine works amazingly and the joints are doing what I want.

    However, I tried to create a very basic animation where the centipede's body parts were swinging around by putting some rotation on the various body parts in key frames. That's where the bad surprise arrived: the rotation behavior of the hinge joints originated from the physics engine stopped working.
    By playing around with the inspector, it looks like as soon as the "swinging" animation state is added to the animator state graph it locks out the rotations of the rigidbody, even if the animation state is never triggered/transitioned to. By removing the state from the graph, everything returns back to normal.

    I tried to google the issue and played around with "apply root motion", "write defaults" and such with no luck. I'm wondering if what I'm trying to achieve (having the physics engine work on the bodies of the centipede while no animation is running, and the animation taking the scene and the priority when it's triggered/transitioned to) is supported in some ways that I ignore or if the animation engine is acting like this by design.

    What I learnt by research is that by executing script-based physics logic in the LateUpdate() call it is possible to "trick" the animation engine, since the animation frames have already been generated at that point. However, I wonder if there is a way to force the physics engine for that particular GameObject to run in the LateUpdate() lifecycle method, solving my issue.
     
    Deleted User and Ultroman like this.
  2. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    156
    Using LateUpdate() didn't work on my end, totally broken animator mess...