Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 3D-Magic-VR · Aug 05, 2011 at 09:17 PM · listarraysanimationcurve

Using AnimationCurve in List. or Builtin Arrays

Hi everyone, I have this little trouble, using the AnimationCurve in builtin arrays don't keep the modified values, if I try to retrieve the values of any curve the result are like if I put this(AnimationCurve.Linear(0,0,1,1)) every time, my question is: How can I keep those values even if I change from one scene to another?, I ask this because I'm trying to use a multiple animation curve to manipulate some values over time using the "CustomEditor" to make an Editor Tool.

The idea is to use something like this:

 var theCurve : AnimationCurve[]= new AnimationCurve[5];

 for (i = 0; i < theCurve.length; i ++) {
     theCurve[i] = EditorGUILayout.CurveField("Some Name", theCurve[i]);
 }

Any help will be very appreciated.

Thanks a lot to eveyone who can help me.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by 3D-Magic-VR · Sep 01, 2011 at 10:25 PM

Hi every one, I found a solution very interesting about this, the solution is:

 // This will be "Main Script".
 var animationContainer = new List.<AnimationParameters>();
 var howManyAnimations = int;

 function Update () {
     if (howManyAnimations > animationContainer)
         animationContainer.Add(AnimationParameters);
 }


 // This will be "AnimationParameters" script.

 class AnimationParameters {
     var curveAnim : AnimationCurve;
 }

This way you can use multiple animation curves and every curve keeps the values without loosing them if you change from one scene to another.

You can check this to see how it's applied. ;-)

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 Bunny83 · Aug 05, 2011 at 10:31 PM

Where is "theCurve" declared? On a script attached to a GameObject? In this case make sure you don't override the array somewhere. You should use the Reset function to initialise the array. Reset is only called once when the script instance is attached or when you rightclick the component and select "Reset".

If you declared the array in a custom editor / inspector class that wouldn't be a good idea. This class instances are recreated everytime it is reopened. These classes aren't meant for saving static data. Save them to an asset that is serialized.

Some more information what you're actually trying to accomplish would help.
Do you create a custom inspector for a script of yours or a general EditorWindow like the animation window? Where is the data stored?

edit

Ok since Unity can't save AnimationCurves you have to use an AnimationClip that holds the curves.

Normally when assigning AnimationCurves to an AnimationClip you have to specify a relative transform path, a component and a property that is animated by this animation curve. I just want to store the curves and don't care about the clip itself. To be able to store multiple clips i just used the array index as path-string.. xD

function OnInspectorGUI() { if (Target.test == null) { Debug.Log("Created Clip"); Target.test = new AnimationClip(); } var curves = AnimationUtility.GetAllCurves(Target.test); var CC = new AnimationCurve[5]; for (i = 0; i < curves.length; i ++) { CC[i] = curves[i].curve; }

 for (i = 0; i &lt; CC.length; i ++)
 {
     if (CC[i] == null)
     {
         Debug.Log("Created curve");
         CC[i] = AnimationCurve.Linear(0,0,1,1);
     }
     CC[i] = EditorGUILayout.CurveField("Some Name", CC[i]);
     Target.test.SetCurve("Name"+i,Transform,"",CC[i]);
 }

}

You should read the manual to understand AnimationUtility.GetAllCurves and SetCurves

It's not really nice but the only alternative is to save the keyframe data "manually" with types that are serializable.

Comment
Add comment · Show 5 · 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 3D-Magic-VR · Aug 05, 2011 at 10:43 PM 0
Share

Thanks for the reply, the situation is this:

The variable is in the game object, I made a function to set the size of the array, then use this stuffs in an editor script, all draw fine even the curve can be modified, but when I open another scene and return to where the script is, there just re-initialized, the changes are gone. There's some way to keep the values?, thanks again for your answer.

avatar image Bunny83 · Aug 05, 2011 at 11:01 PM 0
Share

The values should be automatically serialized / deserialized. Where and when do you initialize the array?

avatar image Bunny83 · Aug 05, 2011 at 11:21 PM 0
Share

Well, i've actually tested it myself and unfortunately Unity can't serialize AnimationCurves.

On this page they listed all serializable types:
http://unity3d.com/support/documentation/ScriptReference/SerializeField.html

avatar image Bunny83 · Aug 05, 2011 at 11:45 PM 0
Share

Finally i've got it working. Unity can't directly save AnimationCurves, only AnimationClips are serialized. It's just a quick and dirty test, but it works ;)

I will edit my answer

avatar image 3D-Magic-VR · Aug 07, 2011 at 05:54 PM 0
Share

Thanks for your help, I'll try it, it's not exactly what I want but hopes works fine to me, even if I find some other way to do that I´ll share it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

[C#]Inventory script help. 3 Answers

UnityScript for unique simpleJSON lists 0 Answers

Populating a list in the editor 2 Answers

Adding Item object to Inventory List 0 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