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 robinking · Feb 22, 2011 at 12:17 PM · animationeditoranimationcurvecs1061

Need help with editor script to copy animation data into individual curves

I'm trying to code an editor script to take an animation I build in the Animation Editor, and copy its individual curves into the AnimationCurve public variables of a script attached to a GameObject. (I'm doing this as I want access to the curve data itself, but it's easier to build the animations in the editor.) I'm new to editor scripts. I've had a look at this answer, to get me started. So far I've modified it to the following:

using UnityEditor; using UnityEngine; using System.Collections;

public class CopyCurves { const string duplicatePostfix = "_copy";

[MenuItem("Assets/Copy Animations To Curves")] static void CopyCurvesToIndividualCurves() { // Get selected AnimationClip AnimationClip imported = Selection.activeObject as AnimationClip; if (imported == null) { Debug.Log("Selected object is not an AnimationClip"); return; }

 // Copy curves from imported to copy
 AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
 for (int i = 0; i < curveDatas.Length; i++)
 {
     if (curveDatas[i].path=="Joint_0" && curveDatas[i].propertyName=="m_LocalRotation.x") {
         AnimationCurve anim = curveDatas[i].curve;

         System.Object army = GameObject.Find("/Arm").GetComponent<ArmCurves>();

         Keyframe[] keyz = anim.keys;
         foreach (Keyframe key in keyz) {
             army.joint0x.AddKey(key); // THIS IS THE PROBLEM LINE
         }

     }

 }

 Debug.Log("Copying curves is done");

}

}

The GameObject's script ("ArmCurves") is simply this:

using UnityEngine; using System.Collections;

public class ArmCurves : MonoBehaviour { public AnimationCurve joint0x; }

I get the following error on comilation: Assets/Editor/CopyCurves.cs(36,38): error CS1061: Type object' does not contain a definition forjoint0x' and no extension method joint0x' of typeobject' could be found (are you missing a using directive or an assembly reference?)

Firstly, can an editor script access variables belonging to a script attached to a GameObject? Secondly, am I mistaken that I can copy the curve data into the exposed AnimationCurve and see it in the curve editor after running this script? And thirdly, if 1 and 2 are okay, what am I doing wrong in the script above?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ejlersen · May 10, 2011 at 06:09 PM

I haven't played that much with animations, but I'm quite sure the reason is that your army variable has been set to the type System.Object. It should be of the type ArmCurves, so cast it to that and you should get permission to access joint0x.

About you questions:

1) Yes, however you can't access scripts in the Editor folder from other scripts (not in the Editor folder). 2) Yes and no, you can copy it into the exposed AnimationCurve joint0x variable, however I don't think it will be viewable in the Animation editor. You can apply it to the animation on the game object and it should be viewable from there. Try taking a look at AnimationUtility.

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

No one has followed this question yet.

Related Questions

AnimationClip.SetCurve not setting a curve... 0 Answers

EDITOR: How to Change Animation Curve Colors 0 Answers

Curve fields in editor scripts 1 Answer

Why can't I edit animation curves imported from Maya? 1 Answer

Can't add property to animation 4 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