|
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: Any help will be very appreciated. Thanks a lot to eveyone who can help me.
(comments are locked)
|
|
Hi every one, I found a solution very interesting about this, the solution is: 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. ;-)
(comments are locked)
|
|
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. 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
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. 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.
Aug 05 '11 at 10:43 PM
3D-Magic-VR
The values should be automatically serialized / deserialized. Where and when do you initialize the array?
Aug 05 '11 at 11:01 PM
Bunny83
Well, i've actually tested it myself and unfortunately Unity can't serialize AnimationCurves. On this page they listed all serializable types:
Aug 05 '11 at 11:21 PM
Bunny83
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
Aug 05 '11 at 11:45 PM
Bunny83
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.
Aug 07 '11 at 05:54 PM
3D-Magic-VR
(comments are locked)
|
