animancer icon indicating copy to clipboard operation
animancer copied to clipboard

Null Exception - MixerTransition has destroyed clip

Open wrymn opened this issue 9 months ago • 2 comments

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

wrymn avatar May 03 '24 07:05 wrymn

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 avatar May 03 '24 07:05 KybernetikGames