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 digiDave · Mar 10, 2015 at 08:53 PM · animationjavascripteditor-scripting

Add animtion clip through editor

I am trying to create and then add animation clips to selected game objects through the editor using js. I have the following code:

 @MenuItem ("Custom/AddClip")
 
 static function AddAnimationClip(){
 
 for (var obj : GameObject in Selection.gameObjects){
     anim = obj.GetComponent.<Animation>();
 
     // Animates the x coordinate of a transform position.
     // Create the curve.
     var curve : AnimationCurve = AnimationCurve.Linear(0, 1, 2, 3);
 
     // Create the clip with the curve.
     var clip : AnimationClip = new AnimationClip();
     clip.legacy = true;
     clip.SetCurve("", Transform, "localPosition.x", curve);
     
     // Add and play the clip
     anim.AddClip(clip, "test");
     anim.Play("test");
      }
 }

This adds the newly create animation clip to "Animations" area of the animation component as "Element 0" but does not add it to the "Animation" area. This means the animation clips does not play when running in game mode but will play if you press play in the animation window with the game object selected. I'm using Unity 5 but the same happens in 4.6.

I have attached an image to help explain what I am trying to do.

alt text

Any help would be appreciated.

addinganimationclips.jpg (57.6 kB)
Comment
Add comment · Show 3
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 AmazingDeveloper2 · Mar 10, 2015 at 10:06 PM 0
Share

Not sure, that understood your question, but did you tried use component Animator ins$$anonymous$$d of the Animation?

avatar image digiDave · Mar 12, 2015 at 08:53 PM 0
Share

I have tried using Animator ins$$anonymous$$d of Animation but I didn't get very far as most of the unity docs scripting examples refers to Animation when talking about adding animation through scripts.

avatar image digiDave · Mar 19, 2015 at 09:31 PM 0
Share

Bump, anyone?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KickBack · Mar 20, 2015 at 01:22 PM

I believe that animation.clip = sets the desired animation as the selected animation. So you need to add this:

anim.clip = clip;

I'm certain that this works while playing. Not sure if this works in editor updating the window.

Comment
Add comment · Show 2 · 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 KickBack · Mar 20, 2015 at 01:25 PM 0
Share

you could also do that with mecanim and animator using AnimatorState$$anonymous$$achine inside editor scripts.

avatar image digiDave · Mar 20, 2015 at 02:19 PM 0
Share

Thanks, this works great, and yes it works within the editor script.

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

Can I make animations snap to a frame? 1 Answer

How to edit Animation Clip Settings using an editor script 2 Answers

How to play mecanim animations in Editor mode? 2 Answers

2d Sprite Animation Editor Scripting. 2 Answers

Instance gotten with reflection is throwing a null reference when trying to access its fields with reflection. 1 Answer


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