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
1
Question by AmbroseFurback · Apr 01, 2013 at 08:28 PM · propertydrawergeneric list

PropertyDrawer with a Generic List Property?

I've been working on a PropertyDrawer for my Attribute class:

 [System.Serializable]
 public class Attribute : IGUIItemInfo
 {
     public EAttributeName     attributeName;
     public float            max;
     public float             current;
     public float            baseValue;    
     public List<Modifier>     mods;

My issue is with the mods property. With the default inspector I can see the mods just fine. When I try to add them to my custom PropertyDrawer, I just see a fold icon and no contents:

 EditorGUI.PropertyField (r, property.FindPropertyRelative ("mods"), GUIContent.none);

The default shows up as follows:

alt text

The custom one shows this:

alt text

How would I code for the mods to show up like the first example?

untitled.png (4.5 kB)
untitled2.png (2.9 kB)
Comment
Add comment · Show 1
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 matthewhoyes18 · Dec 04, 2013 at 10:14 PM 0
Share

I'm looking for a way to make property drawers for a List too. No luck so far!

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Tortuap · Nov 02, 2015 at 09:40 PM

Simply don't forget to set the latest parameter of method EditorGUI.PropertyField :

 EditorGUI.PropertyField ( ..., includeChildren:true );

Comment
Add comment · Show 4 · 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 Bunny83 · Nov 03, 2015 at 01:26 AM 0
Share

Yep, that should do ^^.

 +1
avatar image chuwilliamson · Apr 28, 2017 at 06:06 AM 0
Share

4 hours... thank you very much..

avatar image Tortuap chuwilliamson · Apr 28, 2017 at 08:00 AM 0
Share

You are welcome :)

avatar image PNUMIA-Rob · Mar 27, 2018 at 03:26 PM 0
Share

Necro revival -- but damn man, thanks! :D

avatar image
-3

Answer by BlinksTale · Aug 08, 2014 at 04:31 PM

The default one uses an array, not a list. That's why it has a set size which you must define at the start. Lists are dynamic, they can change sizes easily, but regular arrays are not.

You can change this by switching this:

 public List<Modifier> mods;

to this:

 public Modifier[] mods;

If you aren't familiar with arrays, be sure to read up on them.

http://docs.unity3d.com/ScriptReference/Array.html

http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx

Although I would guess more of the problem is in understanding what makes properties appear that way in the editor, not how arrays work. :)

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 Bunny83 · Nov 03, 2015 at 01:34 AM 1
Share

Actually from a serialized data point of view there's not difference between arrays and Lists inside the editor. Arrays and generic Lists are displayed exactly the same way. The problem here is that a list / array doesn't show up as a single serialized property. The property actually has child properties.

Some useful things in the SerializedProperty in relation to lists arrays are:

  • hasChildren

  • hasVisibleChildren

  • isExpanded

  • CountInProperty

  • Next note the bool parameter

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

17 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

Related Questions

Set size of generic list via script? 0 Answers

EditorGUI.IntField always 0 after GameStart 0 Answers

Select a readonly value from dropdown using PropertyDrawers 0 Answers

CustomAttribute on Class or Method ( EDIT: Button to call methods) 2 Answers

GetPropertyHeight infinite recursion on drawer 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