Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Alismuffin · Jan 27, 2015 at 06:51 AM · animationeditorinspectorpreviewextension

Animation Preview in Custom Asset Inspector Window

Hey!

I am making an editor extension and I want to have a box that has a preview of an animated mesh in it.

I got it kind of working, but not completely so I feel really close but can't quite get it!

This displays the GameObject and I can rotate around it by clicking and dragging. The game object does not animate:

 GameObject previewGameObject;
 AnimationClip animationClip;
 Editor myEditor;
 float sampleTime = 0.5f;
 void OnInspectorGUI()
 {
     if(myEditor == null) myEditor = Editor.CreateEditor(previewGameObject);
     if(myEditor.target != previewGameObject)
     {
         Editor.DestroyImmediate(myEditor);
         myEditor = Editor.CreateEditor(previewGameObject);
     }

     AnimationMode.StartAnimationMode();
     AnimationMode.BeginSampling();
     AnimationMode.SampleAnimationClip(previewGameObject, animationClip, sampleTime);
     myEditor.DrawPreview(new Rect(0, 0, 300, 300));
     AnimationMode.EndSampling();
     AnimationMode.StopAnimationMode();
 }

To get the animation to work I have to assign the editor every frame, which is dumb and also stops me from being able to rotate around the object:

     GameObject previewGameObject;
     AnimationClip animationClip;
     Editor myEditor;
     float sampleTime = 0.5f;
     void OnInspectorGUI()
     {
         Editor.DestroyImmediate(myEditor);
         myEditor = Editor.CreateEditor(previewGameObject);
 
         AnimationMode.StartAnimationMode();
         AnimationMode.BeginSampling();
         AnimationMode.SampleAnimationClip(previewGameObject, animationClip, sampleTime);
         myEditor.DrawPreview(new Rect(0, 0, 300, 300));
         AnimationMode.EndSampling();
         AnimationMode.StopAnimationMode();
     }


I have tried a bunch of things, but nothing works as I want to so far!

I hope someone out there has experience in this because this animation preview is quite important to my extension.

Thanks! :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GouravGoyal13 · Feb 05, 2018 at 01:10 PM 0
Share

Hey, did u get any solution for the problem. i am also running into same problem.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by startassets · Mar 12, 2017 at 07:46 PM

@Alismuffin I've just finished my own preview asset, maybe it will be useful for you: https://forum.unity3d.com/threads/powerful-preview.460157/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Squeazer · May 17, 2021 at 11:30 AM

If anyone else is going through the pain of trying to do this, and comes across this answer, here is how it can be done:

 if (clipEditor == null) {
     clipEditor = UnityEditor.Editor.CreateEditor(clip);
     clipEditor.HasPreviewGUI();
 }
 
 GUILayout.BeginHorizontal();
 GUILayout.FlexibleSpace();
 clipEditor.OnPreviewSettings();
 GUILayout.EndHorizontal();
 clipEditor.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(256, 256), EditorStyles.whiteLabel);

You have to call HasPreviewGUI because it initializes some internal stuff (AvatarPreview), for some reason. Calling OnPreviewSettings is optional and draws the buttons above the preview.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to create a custom model preview in an Editor window akin to the one displayed when an FBX is selected? 3 Answers

switching to legacy makes the animation preview tiny 0 Answers

Get default preview for GameObject Editor 2 Answers

Animation field in custom inspector. 1 Answer

How to play animation clip only once in the Animation View 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges