KybernetikGames / animancer

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

Adding a NamedAnimancerComponent to an object without an Animator at runtime causes an error #234

Closed KybernetikGames closed 1 year ago

KybernetikGames commented 1 year ago

Environment

Description

Adding a NamedAnimancerComponent or HybridAnimancerComponent to an object without an Animator component at runtime throws: ArgumentNullException: An Animator component is required to play animations.

Solution

Add this function to AnimancerComponent.cs:

public bool TryGetAnimator()
    => _Animator != null
    || TryGetComponent(out _Animator);

Then add if (!TryGetAnimator()) return; to the start of the following methods:

This fix will be implemented in the next version of Animancer.

Alternatives

KybernetikGames commented 1 year ago

Animancer v7.4 is now available with this fix.