When I display a animation clip in a custom editor window, similar to the following:
clipEditor = UnityEditor.Editor.CreateEditor(animationClip);
clipEditor.OnPreviewSettings();
clipEditor.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(256, 256), EditorStyles.whiteLabel);
The preview clip has a timeline bar - but the timeline only allows scrolling through the first 30 frames (one second) of the clip. Any ideas how I can scroll through the entire clip in the preview?
Thanks!
I also had this problem and found the only hacky way to fix it.
Just call the FixPreviewEditorForAnimation(clipEditor) and it should do the work
private static FieldInfo _cachedAvatarPreviewFieldInfo;
private static FieldInfo _cachedTimeControlFieldInfo;
private static FieldInfo _cachedStopTimeFieldInfo;
private static void FixPreviewEditorForAnimation(Editor editor)
{
if (!(editor.target is AnimationClip clip)) return;
if (_cachedAvatarPreviewFieldInfo != null && _cachedTimeControlFieldInfo != null && _cachedStopTimeFieldInfo != null)
{
var value = _cachedAvatarPreviewFieldInfo.GetValue(editor);
var subValue = _cachedTimeControlFieldInfo.GetValue(value);
_cachedStopTimeFieldInfo.SetValue(subValue, clip.length);
}
else
{
_cachedAvatarPreviewFieldInfo ??= editor.GetType().GetField( "m_AvatarPreview", BindingFlags.NonPublic | BindingFlags.Instance);
if (_cachedAvatarPreviewFieldInfo == null) return;
var value = _cachedAvatarPreviewFieldInfo.GetValue(editor);
if (value == null) return;
_cachedTimeControlFieldInfo ??= value.GetType().GetField("timeControl", BindingFlags.Public | BindingFlags.Instance);
if (_cachedTimeControlFieldInfo == null) return;
var subValue = _cachedTimeControlFieldInfo.GetValue(value);
if (subValue == null) return;
_cachedStopTimeFieldInfo ??= subValue.GetType().GetField("stopTime", BindingFlags.Public | BindingFlags.Instance);
if (_cachedStopTimeFieldInfo == null) return;
_cachedStopTimeFieldInfo.SetValue(subValue, clip.length);
}
}
7 Likes
Really glad I’ve found this tread, spent the whole evening struggling with Odin Inspector & Animation Clip preview. Can someone submit a bug report? This doesn’t seem like intended behaviour for preview windows.
Also coming here to say thank you so much for this, Sologamer. Was having the exact same problem and you provided the turn-key solution! 
CombatMove.cs (3.5 KB)
CombatMoveEditor.cs (13.7 KB)
Hello, thanks to your effort I was able to finalize this curated CombatMove tooling for fighting games or those that require advanced logic to apply to clips, a scriptable object with an editor preview of the clip with definitions for hitbox/combo windows. Again, thanks!