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
3
Question by Gareth Rees · Mar 17, 2011 at 08:20 PM · animationeditor-scripting

Play animation in the editor?

I'm working on support for animation of mouth movements. The animator needs to be able to watch the mouth movement animation while listening to the audio sample. How can I support this in the Unity editor? It's easy to program a GUI button to play the audio sample, but how do I play the animation in the editor?

Here are some approaches I've considered and couldn't make work:

  • Use the playback feature of the Animation Inspector. (Sadly I have no idea how to do this: there seems to be no script interface for this.)

  • Use AnimationUtility.SetAnimationEvents to place an event at the start of the animation that calls a function that plays the audio. (But the event does not get called when playing the animation from the inspector.)

and here are some approaches I'm still considering:

  • Make an ExecuteInEditMode script. Look at EditorApplication.timeSinceStartup in its Update method. Call AnimationUtility.GetAllCurves to get the list of curves for the animation of interest. For each curve, call AnimationCurve.Evaluate to get the value for the current time. Apply this value to the appropriate transform. (Yuck!)

  • Abandon the idea of trying to play back the animation in the editor. Instead, set some variables, set EditorApplication.isPlaying = true, and arrange to play the animation and the sample from the game. (Slow to start, and causes an inconvenient window switch in the editor.)

  • Instead of editing the lip-syncing animation in edit mode, edit it in play mode using a special mode of the game. In play mode it's easy to play the animation synchronized with the audio. (This works. However, edits you make during play are lost when you exit unless you remember to "Apply" them to a prefab. Perhaps I could use EditorUtility.ReplacePrefab to save changes?)

What's the best approach? Is there a better idea that I've missed?

(A similar question, but no answers: Play animations in editor.)

Comment
Add comment · Show 2
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 DaveA · Mar 17, 2011 at 11:00 PM 0
Share

I was just running into this same issue today. Would REALLY like to preview a) the raw animation from FBX and b) the individual 'splits' I create from them

avatar image Gareth Rees · Mar 18, 2011 at 10:13 AM 0
Share

If you just want to preview the animations, then you can play them in the animation inspector. (But if you want to do something more complicated that needs scripting, then I sympathize.)

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Paulius-Liekis · Mar 21, 2011 at 09:00 AM

Your first idea is closest to the answer, but a little bit overcomplicated. Just set appropriate time on animation state(s) and call Animation.Sample.

Comment
Add comment · Show 3 · 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 Gareth Rees · Mar 23, 2011 at 11:07 AM 0
Share

I tried that first. Animation.Sample has no effect in edit mode for me.

avatar image Paulius-Liekis · Mar 23, 2011 at 12:34 PM 0
Share

Really? I tried it in AssetPostprocessor and definetelly works there. If Animation.Sample doesn't work, then you should submit a bug with $$anonymous$$i repro (and post case number here).

avatar image jahroy · Nov 22, 2011 at 10:01 PM 1
Share

This only works for me if I add a call to Animation.Play() after setting the time on the AnimationState (before caling Animation.Sample())

avatar image
2

Answer by neonfire · Jul 12, 2011 at 02:32 PM

It seems that animation.sample doesn't work, but if you call gameObject.SampleAnimation(clip, time) then it works fine in editor mode.

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
1

Answer by breakeren · Dec 20, 2011 at 11:28 PM

use AnimationUtility.StartAnimationMode() to emitate the mode of the AnimationWindow

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get a list of clips in an animation component from script. 1 Answer

Issue with a Mecanim motion reference in synchronized layers 0 Answers

Animation Editor Window – Get Active Clip Info 1 Answer

UnityEditor script, retrieve all the AnimatorControllers 1 Answer

Creating Editor 2D Animation Preview 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