KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
63 stars 8 forks source link

Using ClipTransitions and event callbacks for multiple characters #310

Closed The-Ash closed 11 months ago

The-Ash commented 11 months ago

Seems like all the examples are for using Animancer for 1 character that are only using their own animations.

When i try to create a system that all characters will use to play their own animations with their own event callbacks everything starts to feel messy and i encounter errors and unintuitive behavior...

One of the "easiest" solutions is to use UnShared fields, but it seems just like a way to double all the animation assets in your project, which requires a lot of manual clicks and creates a lot of clutter.

I would be really glad to see an example for how to use normal ClipTransitions fields to play unshared transitions on multiple units + assigning unshared event callbacks to them.

KybernetikGames commented 11 months ago

Using normal transition fields in components attached to your character prefab avoids the issue because every instance of the prefab will already have its own copy of the transition.

If you want to define your transitions in a shared location and don't want to use individual transition assets then you're most likely making a single ScriptableObject to hold all your transitions. In that case, the easiest solution is generally to just have each character Instantiate their own copy of that asset. The obvious downside with that is the memory cost of having duplicates of all that data for each character where individual UnShared fields only duplicate the events.

This thread has an idea for a centralised event binding system which would avoid sharing issues since you wouldn't be adding events directly to the individual transitions. I hope to implement something like that for Animancer v8.0 but I haven't been able to come up with a solution to the parameters issue I explained in the last post.