KybernetikGames / animancer

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

Syncing Animations In Animancer #352

Closed mubarakalmehairbi closed 5 months ago

mubarakalmehairbi commented 5 months ago

I am using Animancer in my online game and I would like to know how you suggest I network my animations in a way that does not affect performance much. I read the following link: https://kybernetik.com.au/animancer/docs/manual/fsm/overview#networking. The link recommends that I sync my state machine (I think you mean my own coded state machine) but I want to sync the animation without the logic. Why? Because the logic that I wrote in my state machine is specific to the client that owns the gameobject.

How do you recommend I sync the animations without affecting the performance much? One solution that comes to my mind is the following code:

// called on other players when owner's animation clip changes
void OnAnimationClipChange(string clipName, float fadeIn) { 
    AnimationClip clip = MyAnimationDatabase.Find(clipName);  // finds the clip from its name
    animancerComponent.Play(clip, fadeIn);
}

OnAnimationClipChange will be called everytime a change in animation clip is detected. Is there a better solution?

KybernetikGames commented 5 months ago

That should work well enough without notably affecting performance.

You might be able to get better synchronization by including a timestamp from when the event occurred so that the clients can skip the animation forward a bit. I've never tried something like that though, so I don't know how it would work specifically.

mubarakalmehairbi commented 5 months ago

Thanks, I may have some more questions about networking animancer in the future but I will close the issue for now.