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
2
Question by 5argon · Jun 27, 2015 at 01:20 AM · inspectorcustom editorpropertydrawercustom inspectorproperty fields

EditorGUILayout.PropertyField cannot draw custom class?

I have a class A that I marked as [Serializable]. In the class it contained 3 public string so if I declare that with public, in the inspector it would show up as 3 string under a drop down.

 [System.Serializable]
 public class A {
 
     public string englishText;
     public string thaiText;
     public string japaneseText;
 
 }

However, I have one bigger class, B that contained many other things I have written custom inspector for. In this class B I also have some instance of public A in it. (Let's say the name of this variable is aProp) I wanted to use A's default inspector style so I think I could use

 SerializedProperty aProp = info.FindPropertyRelative("aProp");

and then

  EditorGUILayout.PropertyField(aProp,GUIContent.none);

I think it would show up as a foldout, but no, only foldout arrow appeared and nothing would happen if I click on it except the arrow will flip pointing downward. Nothing got folded out. Why? Is the PropertyField limited to 1 line so foldout cannot display?

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
6

Answer by karl_ · Aug 11, 2016 at 01:41 PM

If you're just wanting those properties to draw, include the includeChildren = true parameter in your EditorGUILayout.PropertyField call.

If you have a custom editor for class A this approach will not utilize it however.

Comment
Add comment · Show 1 · 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
2

Answer by edwardrowe · Aug 05, 2016 at 04:58 AM

EDIT: Karl's post is definitely the right way to handle this. I'm leaving this post up just in case the code snippet is useful, but please upvote his answer!


I had this same issue with the same foldout behaviour, and I'm not sure why this doesn't work, exactly.

I found a workaround thanks to vexe in this post: http://answers.unity3d.com/questions/907147/unable-to-draw-propertyfield-in-inspector-for-some.html

Here's my code (notice in my case I don't use FindPropertyRelative, since aProp is a member of my class):

 var aProp = this.serializedObject.FindProperty("aProp");
 int startingDepth = aProp.depth;
 // Move into the first child of aProp
 aProp.NextVisible(true);
 do
 {
     EditorGUILayout.PropertyField(aProp, true);
     aProp.NextVisible(false);
 // Quit iterating when you are back at the original depth (you've drawn all children)
 } while (aProp.depth > startingDepth);

If anyone knows a better way or at least knows why EditorGUILayout.PropertyLayout on the Serialized type with Serialized children doesn't work, I'd still love to know.

Comment
Add comment · Show 1 · 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 TobiasLuckeyPDX · Jun 21, 2020 at 09:47 AM 0
Share

Awesome! I used this, but with EditorGUI ins$$anonymous$$d, to make a ReadOnly PropertyDrawer that properly displayed custom class PropertyDrawers, thanks!

Interesting that it's still relevant 4 years later.

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Inspector Overlapping Text Label at a Position 1 Answer

Draw on Multiple Lines with EditorGUI 1 Answer

Custom tree-like editor 0 Answers

Property Drawer SerializedProperty is null 2 Answers

Custom Inspector "Multi-object editing not supported" 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