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
3
Question by ruudlenders_Legacy · May 29, 2012 at 10:29 PM · custom editorenumeditorguilayoutserializedpropertypropertyfield

How to create a new SerializedProperty?

Recently Custom Editors in Unity caught my attention. Now I'm having a small problem.

I'm currently making a custom editor for a script with 5 properties. The first property is a color value, and will always be visible. The folowing enum should also be visible:

 private enum MaterialType { Color, Pattern }

The other four properties should show up when you select the "Pattern" value. I'm using this code to show my enum:

     MaterialType materialType = MaterialType.Color;
     EditorGUILayout.PropertyField(materialType, new GUIContent("Color or pattern?"));

I'm getting this error: Cannot convert type 'TileObjectEditor.MaterialType' to 'UnityEditor.SerializedProperty'. I understand this error message, and my question is how to get the enum value into a SerializedProperty.

Note that the enum is not included in the base script itself. It is only needed in the editor script, so I can't use serObj.findProperty(...). I could solve this all by moving the enum to the base script, and just use serObj.findProperty("MaterialType"), but since MaterialType is unrelevant there, I'm looking for another way.

Comment
Add comment · Show 2
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 ruudlenders_Legacy · May 29, 2012 at 09:30 PM 0
Share

I managed to pull it off by using EditorGUILayout.EnumPopup, but this "popup" looks different than a PropertyField, and it doesn't have a label. And I'm curious about the alternatives.

avatar image whydoidoit · May 29, 2012 at 10:56 PM 0
Share

Yep I was about to suggest you do just that - also interested!

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

serializedObject with EditorGUILayout.Popup in C# 1 Answer

Custom Editors : EnumFields, Proper Use Of 0 Answers

Custom editor struggle - "Invalid iteration - (You need to stop calling Next when it returns false)" 0 Answers

How to insert an element of specific type to a list as serializedProperty? 1 Answer

CustomPropertyDrawer undoable properties 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