Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Custom animation rigging constraint weight not bind to animation stream property in player build

Discussion in 'Animation' started by closer_ex, Aug 31, 2023.

  1. closer_ex

    closer_ex

    Joined:
    Feb 8, 2022
    Posts:
    1
    This is actually an animation rigging related issue, but as you can see, there is not many discussions going on there, if any.

    I'm trying to create a mod that implements animation rigging for fpv arms for 7daystodie, which creates rig builder and build rig layers through script at runtime. It works pretty well with those built-in rig constraints, but I eventually had to add some custom constraints to deal with specific issues.

    These constraints works without any problem in editor play mode, however when I build and bind them in game, they take no effect at all, no error or warning produced. To narrow down the issue, I deleted the burst compiled dll and modified
    RigSyncSceneToStreamJob.ProcessAnimation
    in Unity.Animation.Rigging.dll with dnSpy as follows to print some info about the animation property bindings:

    Code (CSharp):
    1.         public void ProcessAnimation(AnimationStream stream)
    2.         {
    3.             this.transformSyncer.Sync(ref stream);
    4.             this.propertySyncer.Sync(ref stream);
    5.             this.rigWeightSyncer.Sync(ref stream);
    6.             this.constraintWeightSyncer.Sync(ref stream);
    7.             NativeArray<float> nativeArray = this.rigWeightSyncer.StreamValues(ref stream);
    8.             NativeArray<float> nativeArray2 = this.constraintWeightSyncer.StreamValues(ref stream);
    9.             NativeArray<PropertySceneHandle> sceneHandles = this.constraintWeightSyncer.sceneHandles;
    10.             NativeArray<PropertyStreamHandle> streamHandles = this.constraintWeightSyncer.streamHandles;
    11.             for (int i = 0; i < sceneHandles.Length; i++)
    12.             {
    13.                 if (!sceneHandles[i].IsValid(stream) || !sceneHandles[i].IsResolved(stream))
    14.                 {
    15.                     Debug.Log(string.Format("Rig Sync Scene To Stream Job: scene handle {0} is {1} and {2}", i, sceneHandles[i].IsValid(stream) ? "valid" : "invalid", sceneHandles[i].IsResolved(stream) ? "resolved" : "unresolved"));
    16.                 }
    17.                 if (!streamHandles[i].IsValid(stream) || !streamHandles[i].IsResolved(stream))
    18.                 {
    19.                     Debug.Log(string.Format("Rig Sync Scene To Stream Job: stream handle {0} is {1} and {2}", i, streamHandles[i].IsValid(stream) ? "valid" : "invalid", streamHandles[i].IsResolved(stream) ? "resolved" : "unresolved"));
    20.                 }
    21.             }
    22.             int num = 0;
    23.             int j = 0;
    24.             int length = nativeArray2.Length;
    25.             while (j < length)
    26.             {
    27.                 if (j >= this.rigConstraintEndIdx[num])
    28.                 {
    29.                     num++;
    30.                 }
    31.                 int num2 = j;
    32.                 ref NativeArray<float> ptr3 = ref nativeArray2;
    33.                 ref NativeArray<float> ptr4 = ref ptr3;
    34.                 int num3 = num2;
    35.                 ptr4[num3] *= nativeArray[num] * this.rigStates[num];
    36.                 j++;
    37.             }
    38.             AnimationStreamHandleUtility.WriteFloats(stream, this.modulatedConstraintWeights, nativeArray2, false);
    39.         }
    and here is the output:
    The index belongs to those custom rig constraints. It seems the weight binding is not resolved for scene handle and invalid for stream handle.

    One of the constraints is uploaded in the attachments, which takes a list of source objects and a list of constrained objects and sync their world position and rotation one by one. Other properties seems to be streamed properly, because if I remove the weight check in ProcessAnimation the rest of the codes comes back to life.

    Mod assemblies are loaded with Assembly.Load calls and I read it somewhere that doing this could cause issues with some unity features such as serialization, so I tried moving the assembly to Managed folder but the result remains the same.

    I apologize for posting a modding question in this forum, but I've searched everything I can think of and still can't find any clues.
     

    Attached Files:

  2. DidaFM

    DidaFM

    Joined:
    Apr 17, 2018
    Posts:
    2
    Did you manage to resolve this issue? I'm having the same one. A custom constraint I've implemented works perfectly in Editor but it doesn't work in builds.