I am working on a project using both Animancer and Animation Rigging. They mostly work nicely together, but, as described here, there is one problem: When you add a new AnimancerState
to the component, Animator.Rebind()
gets called, and that resets the weights of all AnimationRigging constraints to their initial value. So, if those weights have been modified at runtime, you lose those modifications.
Now, Kybernetik is kind enough to suggest two workarounds (again, see this link), but, as he points out, neither are very convenient. I already have a slightly-convoluted-but-not-too-awful plan for implementing the second one (caching and reapplying the constraint values when needed), but I was thinking that the first one (creating all the states on startup) is much neater.
The plan for that would be to have a wrapper class around AnimationClip
, which registers a new state on the AnimancerComponent
when the game starts. That way, the whole solution is just to find every case where I have a serialized AnimationClip
, and replace it with this new wrapper.
And so we get to the question. Is there a way I can do this? At first I thought about using ScriptableObjects
, since they have an Awake()
method, but of course that means the ScriptableObject
would need a reference to the scene object that contains the AnimancerComponent
... and that simply does not work when you can have, for example, many instances of the same prefab that all use the AnimationClip
, each one with its own AnimancerComponent
.
My current hunch is that there might be a way to create the wrapper class as a serialized System.Object
(that way, it can be serialized by value and sit inside the prefab itself, and so find the AnimancerComponent
in its own hierarchy) that does it. But, of course, the problem then becomes that a System.Object
does not have a Start()
or Awake()
method that can be used to initialize the whole thing automatically. My last bullet here would be to use System.Reflection
to find all instances of the class on startup and call an Initialize()
method... but, man, do I not want to do that.
Any ideas for how to solve the problem would be appreciated. However, as I said, I do already have plans that would work, so I guess what I'm really looking for is not just a soultion, but a solution that is not confusing and ugly.