bdunderscore / modular-avatar

Other
496 stars 65 forks source link

When the `Unity Timeline` window exists, entering play mode will clear animation curves when using `AnimationClip.SetCurve` in conjunction with `AnimationUtility.SetObjectReferenceCurve` #950

Closed ColorlessColor closed 2 months ago

ColorlessColor commented 2 months ago

Test Environment

Issue Description

Reproduction Steps

  1. Create a VRChat Avatar project and install Modular Avatar.
  2. Open a scene, put in a avatar and a clothes prefab which is using MA Merge Armature. Assuming the Unity scene is as follows, with all GameObjects activated:
    AvatarRoot
    Armature
    ClothesUseMA
    Armature            // `MA Merge Armature` on this
      Hips
        skirtPbRoot     // phys bone of skirt
    SkirtMesh
  3. Record an animation clip that includes:
    • Deactivating AvatarRoot/ClothesUseMA/Armature/Hips/skirtPbRoot (this is a float curve^1).
    • Changing the material of AvatarRoot/ClothesUseMA/SkirtMesh (this is an object reference curve^2).
  4. Place this animation clip in any playable layer (e.g., FX).
  5. Open Unity Timeline window.
  6. Click the Play button.
  7. Check the animation clip that has been rewritten by MA Merge Armature.

Expected Behavior

Actual Behavior

Possible Cause

https://github.com/bdunderscore/modular-avatar/blob/0806c621c5298fa2ec89d2590e8015f6a84fcf3a/Editor/Animation/PathMappings.cs#L248-L262

PathMappings.ApplyMappingsToClip is used to rewrite animation clips' paths associated with GameObjects modified by MA Merge Armature.

The issue arises when SetCurve is first used to write float curves, followed immediately call a AnimationUtility.SetObjectReferenceCurve. In the provided reproduction environment and steps, this results in all animation curves in newClip being cleared (I really don't know why).

The animation curve lost occurs only when the following conditions are met simultaneously:

The issue can be bypassed by the following methods:

Notes

This issue does not affect Manual bake avatar or uploading using the VRChat Avatar SDK.

The issue has only been verified on Unity 2022.3.22f1 and has not been tested on any other versions. Only tested on my Unity installation (I tried reinstall it).

I suspect this is an issue with Unity's animation system itself, and perhaps Modular Avatar does not need to address this specifically, but rather users should avoid using Unity Timeline.

I chose to report this issue because I spent too much time on it and hope that this report will help users who encounter similar issues.

bdunderscore commented 2 months ago

Thanks, I hate it. 🤮

I'll try to repro and fix.

bdunderscore commented 2 months ago

Hmm. I wasn't able to repro the issue with the steps given. That being said, I'll assume there's something else that's a necessary condition and switch to using SetEditorCurve as workaround.

ColorlessColor commented 2 months ago

I created a project for this if anyone needs it:

https://github.com/ColorlessColor/CursedUnityTimeline

bdunderscore commented 2 months ago

Reproed and changing to SetEditorCurve doesn't fix the issue :(

bdunderscore commented 2 months ago

Only reproducible when entering play mode; building manually doesn't cause the issue. I think reload domain might need to be off as well...