• 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
Question by Mikilo · Feb 24, 2013 at 11:15 PM · editoreditor-scriptingpropertydrawer

Why PropertyDrawers shared same values?

Hello everyone,

I used PropertyDrawers to automatically display a list of skills on the inspector. So, I have a ListSkillDrawer and a SkillDrawer. SkillDrawer have some values needed to be saved for its own uses, like a popup index (to remember the position in the popup) or a foldout.

The problem is, when I change one of these values, it is saved in the SkillDrawer, then all drawers received the update. So, I can easily assume that drawers are allocated once for all. But what can we do if we want to brake this rule?

In my example, if we have many skills, one foldout will command all skills's foldout.

Does someone have an answer?

I have an idea on how to do my stuff, but it a pretty ugly trick. Here is my explanation. I wrote the ListDrawer, so when I'm calling PropertyField to draw my children, I can send them an iterator by the label. Thus, SkillDrawers will saved popup's index and fold in an array.

Comment

People who like this

0 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 Mikilo · Feb 25, 2013 at 02:39 PM 0
Share

Does someone have an idea?

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by Mikilo · Aug 31, 2015 at 02:58 PM

After all this time, never thought to solve this topic since I know now the solution.

There is an unique PropertyDrawer per field. Thus it is shared. End of the story.

Comment

People who like this

0 Show 0 · 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

Answer by poday · Apr 09, 2013 at 03:22 PM

I found a potential/partial answer, each SerializedProperty has a public isExpanded bool member. This bool has a separate instance for every property, so in theory every property can have it's own separate and independent foldout.

Comment

People who like this

0 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 Mikilo · Apr 09, 2013 at 03:34 PM 0
Share

Are you saying that if I set isExpanded to true or false, multiple drawers will be allocated? O_o "This bool has a separate instance for every property", I don't really understand this sentence.

avatar image poday · Apr 09, 2013 at 03:41 PM 0
Share

Inside the GetPropertyHeight(SerializedProperty property, GUIContent label) and OnGUI(Rect position, SerializedProperty property, GUIContent label) you're given a SerializedProperty, that SerializedProperty has an isExpanded bool: http://docs.unity3d.com/Documentation/ScriptReference/SerializedProperty-isExpanded.html

You still have the single instance of the Drawer class (and shared instances of the attribute class). That's why I mentioned it as a partial solution, there's a single bool per property that you can use in a foldout.

avatar image Mikilo · Apr 09, 2013 at 03:48 PM 0
Share

Oh.. Ok I see. But my problem wasn't really the foldout problem. That was just a visual problem, an example. The real problem is that my drawers musn't shared data at all.

Since february, I've discovered a new way to search solutions. I use ILSpy and take a look into Unity's DLL. It gives me code of methods.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

Draw inspector of array elements? 1 Answer

SerializedProperty with children class fields 2 Answers

Why does my custom property drawer's DragAndDrop add items twice? 2 Answers

How to show type text in EditorGUI.ObjectField? 1 Answer

CustomPropertyDrawer: foldout issues when switching properties (simulating weak references) 0 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