KybernetikGames / animancer

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

Null Exception - MixerTransition has destroyed clip #342

Closed wrymn closed 6 days ago

wrymn commented 3 months ago

When I have defined LinearMixerTransition field, add new clips, assign a clip, and then I delete one of those clip assets from project, the asset (in my case scriptable object with LinearMixerTransition field) is broken after selection and inspector for it will no longer work, thus, I cannot even change the destroyed clip or remove it.

Please note, this appears to be issue only when using Odin Inspector, so not sure if it will be possible to still fix this, event though odin is not part of animancer package, it would be nice if we could support it and avoid this issue :)

image

image
KybernetikGames commented 3 months ago

Replace the TryGetLength method in ITransitionDetailed.cs with this:

public static bool TryGetLength(object motionOrTransition, out float length)
{
    if (motionOrTransition is AnimationClip clip)
    {
        if (clip != null)
        {
            length = clip.length;
            return true;
        }
    }
    else if (TryGetWrappedObject(motionOrTransition, out ITransitionDetailed transition))
    {
        length = transition.MaximumDuration;
        return true;
    }

    length = 0;
    return false;
}

That first if would still pass if the object is an AnimationClip which has already been destroyed so we need to add an explicit null check to make sure it isn't destroyed.

Same for TryGetIsLooping above it:

public static bool TryGetIsLooping(object motionOrTransition, out bool isLooping)
{
    if (motionOrTransition is Motion motion)
    {
        if (motion != null)
        {
            isLooping = motion.isLooping;
            return true;
        }
    }
    else if (TryGetWrappedObject(motionOrTransition, out ITransitionDetailed transition))
    {
        isLooping = transition.IsLooping;
        return true;
    }

    isLooping = false;
    return false;
}
KybernetikGames commented 1 month ago

Animancer v8.0 is now available for Alpha Testing and includes this fix..

KybernetikGames commented 6 days ago

Animancer v8.0 is now fully released.