When I create an Animation Clip with a 2D Sprite,
the preview window of the Animation Clip says “No model is available for preview”.
At this time, if I drag and drop an object with a Sprite Renderer, the animation is rendered normally.
However, if I close and open Unity, I have to drag and drop again.
Is there a way to set an object with a Sprite Renderer as the default model?
My Solution
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class PreviewSetter
{
static PreviewSetter()
{
var previewObject = Resources.Load<GameObject>($"Prefabs/Previewer");
var previewSelector = Type.GetType("UnityEditor.AvatarPreviewSelection, UnityEditor.CoreModule");
previewSelector?.GetMethod("SetPreview", BindingFlags.Public | BindingFlags.Static)
?.Invoke(null, new object[] {
ModelImporterAnimationType.Generic,
previewObject
});
}
}