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 Catlard · Dec 16, 2012 at 08:03 AM · animationeditoranimationcurveeditorguilayout

Curve fields in editor scripts

EDITED: PROBLEM UPDATED.

Hey, so, I've made a script that causes my "LibraryKitchen" script to display in a fun way. But I'm having trouble getting it to display animation curves. My problem is that apparently animation curves cannot be serialized properties, and I don't know how to let my editor script find it. 've looked at the unity script reference, but it just has the example in javascript. Any idea how to do it in c#?

The line in question is towards the end:

 m_animationCurve = m_Object.FindProperty("_curve");


And the error I'm currently getting is:

 Assets/Editor/OptionalEditorScript.cs(18,17): error CS0029: Cannot implicitly convert type `UnityEditor.SerializedProperty' to `UnityEngine.AnimationCurve'

What's my problem? do you know?

     using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof (LibraryKitchen))]
 public class OptionalEditorScript : Editor {
     
     private SerializedObject m_Object;
     private SerializedProperty m_kitchenVar;
     private SerializedProperty m_libKitchenVar;
     private AnimationCurve m_animationCurve;
     
     public void OnEnable() {
         m_Object = new SerializedObject(target);
         m_kitchenVar = m_Object.FindProperty("_kitchenVar");
         m_libKitchenVar = m_Object.FindProperty("_libKitchenVar");
         m_animationCurve = m_Object.FindProperty("_curve");
     }
     
     public override void OnInspectorGUI() {
         m_Object.Update();
         
         EditorGUILayout.Foldout(true, "Kitchen variables");
         EditorGUILayout.PropertyField(m_libKitchenVar);
         EditorGUILayout.PropertyField(m_kitchenVar);
         EditorGUILayout.PropertyField(m_libKitchenVar);
         EditorGUILayout.CurveField(m_animationCurve);
         
         m_Object.ApplyModifiedProperties();
     }
 }

[1]: http://docs.unity3d.com/Documentation/ScriptReference/EditorGUI.CurveField.html

Comment
Add comment · Show 5
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 yoyo · Dec 17, 2012 at 03:20 AM 0
Share

You don't need to pass anything. GUILayoutOption is just if you want to control width/height etc. of the entry field. See http://docs.unity3d.com/Documentation/ScriptReference/GUILayoutOption.html for more info.

avatar image Catlard · Dec 18, 2012 at 02:04 AM 0
Share

hey, yoyo! I've updated the problem. Thanks so much for your help. Unfortunately, I think the problem is actually also my understanding of serialized properties, so I'm still getting the error above. Any clue what's gone wrong, still?

avatar image yoyo · Dec 18, 2012 at 02:18 AM 0
Share

You can just use SerializedProperty and PropertyField for m_animationCurve as well, no need for CurveField once you have a serialized property.

avatar image Catlard · Dec 18, 2012 at 02:49 AM 0
Share

Perfect. Got it, thanks! Please post your comment as an answer so I can credit you for it. You rule the school, yoyo.

avatar image yoyo · Dec 18, 2012 at 05:10 AM 0
Share

Glad it worked, and answer posted. (Note that you can also up-vote comments ;-)

1 Reply

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

Answer by yoyo · Dec 18, 2012 at 05:10 AM

You can either use EditorGUILayout.CurveField to edit an AnimationCurve, or use EditorGUILayout.PropertyField to edit a SerializedProperty (for any property type, including animation curve).

The code in your answer is mixing these up, trying to assign a SerializedProperty to an AnimationCurve variable and then pass it to a CurveField call.

The simplest fix is to make m_animationCurve a SerializedProperty and then use EditorGUILayout.PropertyField to edit it.

(BTW, as a matter of style and clarity, I would suggest renaming OptionalEditorScript to LibraryKitchenEditor, to match the component it is editing.)

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 Catlard · Dec 18, 2012 at 05:12 AM 1
Share

sure sure! I agree about the rena$$anonymous$$g. that was just a quick and dirty solution. like having babies to keep a relationship going. thanks again.

avatar image yoyo · Dec 18, 2012 at 05:35 AM 2
Share

(As a matter of style and caution, I would suggest counselling first, then maybe a dog.)

avatar image Catlard · Dec 18, 2012 at 06:14 AM 3
Share

(As a matter of style and good will, I am giving you a gigantic pixelated Chinese sword. To thank you for your awesome help).

http://imgur.com/$$anonymous$$7D9G

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

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

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

EDITOR: How to Change Animation Curve Colors 0 Answers

How can I define two-dimensional curves? (like: circle) 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