- Home /
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.
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.
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.
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.
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.
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.
Your answer
Follow this Question
Related Questions
Why does my custom property drawer's DragAndDrop add items twice? 2 Answers
How to show type text in EditorGUI.ObjectField? 1 Answer
PropertyDrawer let's dissapear my INT 0 Answers
GetPropertyHeight infinite recursion on drawer 1 Answer
CustomPropertyDrawer: foldout issues when switching properties (simulating weak references) 0 Answers