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 JulesPomme · May 25, 2021 at 01:57 PM · arraypropertydrawercustominspector

PropertyDrawer inside an array

Hi there,

I have a custom property drawer for an object A, that renders exactly as I want. Besides, I have another object B owning an array of A. In the inspector, the property drawer works as expected, but not the "array part" : the usual string "Element 0" that precedes the first object is not here anymore (idem for the following Elements 1, 2, etc.), and I can't collapse each element of the array anymore.

Is there something to do inside the PropertyDrawer (though I guess it's should not take care of the rendering of my object A when it's embedded in an array), or should I make a custom Editor for my object B, or something else?

Here is an image to illustrate: alt text

Thanks in advance for your help!

propertydrawerproblem.png (53.4 kB)
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

1 Reply

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

Answer by CodesCove · May 25, 2021 at 02:46 PM

Custom Property Drawer is ok for this. You just need to iterate the array inside the drawer. Pseudocode:

 SerializedProperty serialized_A_Array= property.FindPropertyRelative("A_Array");
 foreach (SerializedProperty A in serialized_A_Array)
 {
      EditorGUI.PropertyField([GetPropertyHeight], A, ...)
      if (A.isExpanded)
      {
           //Draw the A as you like. Override the GetPropertyHeight() to position the lines correctly
          EditorGUI.PropertyField([GetPropertyHeight], A.FindPropertyRelative("Position");
          // etc..
      }
 }




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 JulesPomme · May 25, 2021 at 03:01 PM 0
Share

Hi, thanks for your answer! You suggest to iterate the array in the drawer, but for now I only have a drawer for A, which doesn't own the array. It's B that owns the array, and I don't have a drawer for B. You then suggest to create a property drawer for B as well?

avatar image JulesPomme JulesPomme · May 25, 2021 at 03:40 PM 0
Share

Thank you again, I've figured out, as you mentioned in my property drawer, I had to use the EditorGUI.FouldOut() method, and then check if property.IsExpanded. Thanks!

avatar image CodesCove JulesPomme · May 25, 2021 at 07:07 PM 0
Share

Great you got it working! I convert my comment to answer.

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

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

Related Questions

SerializedProperty isn't being detected as an array? 1 Answer

How to prevent overlap when using nested arrays in CustomPropertyDrawers? 1 Answer

EditorGUI.IntField always 0 after GameStart 0 Answers

How do I property Drawer? 1 Answer

Custom Editor/Custom Property Drawer combo, breaks Enable button 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