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

Question Multi-Aim constraints jumble character bones after deactivate/activate from a pool.

Discussion in 'Animation Rigging' started by halfpasttense, Dec 19, 2020.

  1. halfpasttense

    halfpasttense

    Joined:
    May 30, 2020
    Posts:
    21
    I'm using a couple of simple Multi-Aim constraints to aim the head and chest of my animated humanoid characters at a certain target. These characters are pooled, so once they die their root GameObject gets set to inactive. Later on, they can be respawned from the pool by setting them active again. My problem is, the Animation Rigging Multi-Aim constraints work just fine the first time a character is spawned, but if they die, get deactivated, then get activated again later, everything is very messed up. The more times they respawn the more messed up it gets. And by messed up I mean the bones controlled by the Multi-Aim constraints get twisted more and more with every respawn until the character is a hunched over jumbled mess. The weight of the rig is set to 0 right before the character dies. Is there something I'm missing on how to properly reset Rigging in this use case?
     
  2. halfpasttense

    halfpasttense

    Joined:
    May 30, 2020
    Posts:
    21
    I updated my project to Unity 2020.2 and the latest Animation Rigging package version but I'm still having this issue. I cannot figure out how to prevent this from happening, short of not pooling the characters and instantiating them from scratch every time. Pooling is a well established pattern and animation rigging should work with it. Can someone from Unity please help me with this?
     
  3. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Are there any warnings/errors in the console when you're reenabling your character?

    What is the pose of the character when you disable the hierarchy? When you enable the animator, it also snapshots the current default pose of the character. If your constraints rely on bones/properties that are not animated directly through clips, then, they'll just read back from the default pose which may not be what you intended.

    Alternatively, try calling `RigBuilder.Build()` before reenabling the Animator to rebuild the Animation Rigging PlayableGraph.
     
  4. halfpasttense

    halfpasttense

    Joined:
    May 30, 2020
    Posts:
    21
    Thank you for your reply. No there aren't any warnings or errors in the console. When I deactivate the character it is at the end of a death animation. I do not ever enable or disable the animator. It stays enabled. I only deactivate/activate the root GameObject of the animated character. This works perfectly fine for everything but the Animation Rigging. All my usual Animator animation clips behave normally after respawn, and the character is in the correct idle animation upon respawn. I have tried calling RigBuilder.Build() under many different circumstances, but so far this has not fixed anything.

    I do see these warnings on the Animator, and they are definitely caused by the Animation Rigging as they do not appear with Rigging removed.
    upload_2021-1-9_0-2-8.png
    But these are there upon the first spawn too when things are working, so I assume this isn't the problem.

    Is this deactivate/activate GameObject pooling with animated humanoid characters something you have tested before with Animation Rigging? I'm wondering if you can recreate it with any rigged character or if there's something specific to mine that's causing it to break.
     
  5. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    We have some issues reported animation C# Jobs introduce offsets to the character when using humanoid. This is due to a retargeting error after having evaluated the constraint. This may explain the issue you're seeing

    https://issuetracker.unity3d.com/is...hacter-makes-it-sink-into-the-ground#comments

    You could try making sure the character is put back in its original position when disabling it to make sure said offset is not introduced.

    Otherwise, I'm fairly certain you won't have the issue with a generic character setup.

    Either way, it would be helpful if you could submit a bug report using the Unity bug reporter so that we can have a look.
     
  6. halfpasttense

    halfpasttense

    Joined:
    May 30, 2020
    Posts:
    21
    Ok I will try to make a sample project showing the bug and submit it.

    By putting the character back into the original position, do you mean the T-pose? What's the correct way to put a an animated humanoid character back into T-pose?
     
  7. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    321
  8. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    321
    hey how about this for a twist...(no pun indented).

    I have a player with a rig for the arms. when i disable and enable player from inspector check box, the arms are indeed now twisted/funky on the rig like you said.

    Animator.Rebind() did not fix it...however, while testing again I accidently triggered Animator.Rebind() on player before ever disabling it, and that puts him in the same twisted arm position as the reported issue...if I were to disable and reenable from inspector.
     
  9. halfpasttense

    halfpasttense

    Joined:
    May 30, 2020
    Posts:
    21
    I was able to fix the issue by calling Animator.WriteDefaultValues() before deactivating the root GameObject of the animated character. I would still consider this a bugged behavior, because simply deactivating/activating the character shouldn't completely mess up any animation rigging on the character. Or at the very least this behavior should be well documented.
     
    Mark-Davis, smonchdev0 and tree_arb like this.
  10. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    @halfpasttense Thank you so much for that!! I had exactly the problem described and was able to implement your suggested fix and verify that everything was working perfectly in less than 2 minutes! :) My animation rig allows NPCs to twist naturally from the waist up and use one arm to aim a pistol while not interfering with the rest of a walking/running animation. As you mentioned earlier, this really does seem like something that should be mentioned in Unity's Animation Rigging docs. Pretty much anyone doing anything serious is going to run up against this. Thanks again!
     
  11. aplusgreenlawn

    aplusgreenlawn

    Joined:
    Nov 14, 2023
    Posts:
    15
    I have a Question I haven't read any of the above, but I think this topic is what I'm looking for because what I wanted to ask is about the Multi-Aim Contraints in Animation Rigging.

    Anyway so my question is, is there a way to test my Aim-Contraint's without having to Play and Stop Playing my Game? I'm having a problem with loading and stopping my game and it's is very irritating starting my game (nothing to do with engine platform) My game start up is not very quick takes like half a minute or more to start then I have to stop to make adjustments then restart again. Is there an easier way of testing my Aim contraint's without starting and stopping Game?
    Also I have a right click Aim Button to start a Virtual ThirdPerson camera view with right shoulder offset, anyway when I'm testing my Aim Constraints I can't keep my Game Player in Aim mode to see how the contraints work with that Aim animation, after I leave game with mouse cursor he goes back to Idle and I can't see how or if my Aim contraints work properly with that Animation position. And when I get the results I want I forget in game mode they don't save on stop so I lose my desired effects, and have to re-do again. I know this seems like I'm just lazy but I have that problem alot im A (Forgetter).

    So the whole thing I'm wondering is if there is some other window or TAB that I cant test my animation Rigging Aim Contraints? Where I do not have to go through all this hassle?