Answered

Child transform is controlled by animator even after dis-parenting

fishwind 5 months ago updated 5 months ago 4

Good day!

Issue:

I have a character that can throw a weapon. The thrown weapon transform is being controlled by the animator even after weapon.transform.SetParent(null).

More description:

1) The weapon is initially the child of character's hand. Character has the animator.

2) At a certain timeframe, animation event is triggered to call:

        - weapon.transform.SetParent(null)

        - isKinematic = false

3) The weapon transforms local values remains the same as before dis-parenting (as it is being controlled by animator)

4) Unable to change any weapon transforms when this occur.

Important note:

- I did not use child-of constraint. Because the thrown weapon should use rigidbody physic

- When this occur during gameplay, disabling the character's animator component could make the weapon move again.

- When this occur during gameplay, dragging around the animation could potentially fix the issue too

- There is no keyframe nor animator on the weapon at all.


Updates
:

I noticed if I rename the weapon name, the issue could be fixed. But is there a better solution?

UMotion Version:
1.20p08
Unity Version:
2019.3.9f1

Answer

Answer
Answered

Hi,

thank you very much for your support request.

Can you check the exported animation (with Unity's Animation Window). Are there any animation curves for the weapon or any of it's child transforms (in any of the animations you play on that Animator)?


Calling Animator.Rebind() after you changed the parenting should release your weapon: https://docs.unity3d.com/ScriptReference/Animator.Rebind.html

Best regards,
Peter

GOOD, I'M SATISFIED
Satisfaction mark by fishwind 5 months ago
Answer
Answered

Hi,

thank you very much for your support request.

Can you check the exported animation (with Unity's Animation Window). Are there any animation curves for the weapon or any of it's child transforms (in any of the animations you play on that Animator)?


Calling Animator.Rebind() after you changed the parenting should release your weapon: https://docs.unity3d.com/ScriptReference/Animator.Rebind.html

Best regards,
Peter

Hi Peter, thanks for the reply!

I've checked the exported animation in Unity Animation Window. I did not find any keys or curves relates to the weapon transform (no child transform also). There are also no other animations containing the weapon transform key frame).

I've also tried Animator.Rebind(). 

Issue 1: It could sometimes fix but only after looping the throwing weapon animation a number of times. 

Issue 2: When .Rebind() is called, the animations will be reset, which looks unnatural.

The weapon was added to the Character through Unity's Hierarchy instead of Umotion's config mode (custom transform). Could this be the cause?

The weapon was added to the Character through Unity's Hierarchy instead of Umotion's config mode (custom transform). Could this be the cause?


UMotion exported a regular animation file and doesn't have any control over what happens afterwards so I don't think that this has anything to do with UMotion. This weird behavior is coming from Unity's Animator component.

By reading the documentation I really do think that Rebind() should work. So this might be a Unity bug. What you could also try as a workaround is enabling/disabling the Animator component (if that is possible in your case as I think this will interrupt any transitions and restart your animation controller states).

If you don't get this solved, try to reproduce this in a new empty Unity project and keep it as simple as possible. If it also doesn't work there, you may want to report this as a bug. The simpler and more to the point your repo project is going to be, the more likely you're going to get a fix from Unity.

Best regards,

Peter

Hi Peter, thank you so much for your detailed explanation! I've fixed it by renaming the weapon, and creating the throw animation again. Still not sure what's the cause tho.

Anyway, I've just given a rating 5/5 on asset store, thank you for being so responsive :)