Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting and getting Body Position/Rotation... warning problem

Discussion in 'Animation' started by Slawomir-Sokol, Aug 2, 2016.

  1. Slawomir-Sokol

    Slawomir-Sokol

    Joined:
    Dec 10, 2013
    Posts:
    12
    Hi

    I'm overriding OnStateMove method of StateMachineBehaviour class and run into an issue.

    I want to manually move a character during jump using his bodyPosition as a 'moving point' instead of a pivot. For that I cache the bodyPosition at the end of each frame, and on the beginning of next frame move the character accordingly so that its bodyPosition will be in proper place.

    This works perfectly and as intended, however on each method call I get a warning:

    'Setting and getting Body Position/Rotation, IK Goals, Lookat and BoneLocalRotation should only be done in OnAnimatorIK or OnStateIK'

    Since my animator is on PhysicsUpdate I get so many of those warning they actually drop the FPS significantly.
    I don't see any reason why accessing bodyPosition in move causes the warning and what should I do to get rid of it. (since I'm overriding root movement and that should be done in Move method)

    Is there any way to disable this warning?
    Or maybe someone has a better way of achieving what I want that will not cause this warning to ocure?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi Slawomir,

    The bodyPosition is updated by the retargeting pass which is right after OnStateMove/OnAnimatorMove. If you read the bodyPosition in OnStateMove/OnAnimatorMove you are reading the value from the last evaluation so you are always one frame late.

    You are overriding the root motion right but the bodyposition is computed right after by the retargeter so the bodyposition could change after the retargeting pass.

    If you still want to do it this way you can disable all the warnings from the animator like this
    Animator.logWarnings = false;
     
    twobob likes this.
  3. SonicTheHedgiehog

    SonicTheHedgiehog

    Joined:
    Nov 15, 2020
    Posts:
    20
    I'm getting the same error but not everything is working as expected. @Mecanim-Dev , instead of disabling the warning how to prevent/fix it? what am i doing wrong? i am following a tutorial