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

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:

        public void ProcessAnimation(AnimationStream stream)
        {
            this.transformSyncer.Sync(ref stream);
            this.propertySyncer.Sync(ref stream);
            this.rigWeightSyncer.Sync(ref stream);
            this.constraintWeightSyncer.Sync(ref stream);
            NativeArray<float> nativeArray = this.rigWeightSyncer.StreamValues(ref stream);
            NativeArray<float> nativeArray2 = this.constraintWeightSyncer.StreamValues(ref stream);
            NativeArray<PropertySceneHandle> sceneHandles = this.constraintWeightSyncer.sceneHandles;
            NativeArray<PropertyStreamHandle> streamHandles = this.constraintWeightSyncer.streamHandles;
            for (int i = 0; i < sceneHandles.Length; i++)
            {
                if (!sceneHandles[i].IsValid(stream) || !sceneHandles[i].IsResolved(stream))
                {
                    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"));
                }
                if (!streamHandles[i].IsValid(stream) || !streamHandles[i].IsResolved(stream))
                {
                    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"));
                }
            }
            int num = 0;
            int j = 0;
            int length = nativeArray2.Length;
            while (j < length)
            {
                if (j >= this.rigConstraintEndIdx[num])
                {
                    num++;
                }
                int num2 = j;
                ref NativeArray<float> ptr3 = ref nativeArray2;
                ref NativeArray<float> ptr4 = ref ptr3;
                int num3 = num2;
                ptr4[num3] *= nativeArray[num] * this.rigStates[num];
                j++;
            }
            AnimationStreamHandleUtility.WriteFloats(stream, this.modulatedConstraintWeights, nativeArray2, false);
        }

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.

9264165–1296351–ForceWorldOverride.cs (2.89 KB)
9264165–1296354–ForceWorldOverrideJob.cs (4.09 KB)

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.