PropertyDrawer for Arrays

Hello Everyone.

Im trying to enhance the editor experience by the use of PropertyDrawers.
My goal is to ann an extra predefined text to the Array inspector.

The background:
I save the content for different languages in my scripts in arrays.
it would be kind of nice if i could see in the editor what index of the array is what language right?

Is there a way to get the index of the drawn property inside of the array?

PropertyDrawers are somehow unaware of their context sometimes. You can’t always get the object it is representing. When it is an array element as in your example, you can get the path of the property as string. It is necessary for you to parse the string and get the array index like that. That’s unfortunately the only way to deal with it as far as I know.

Having implemented many editor extensions in the conventional way, I am making my hands dirty from time to time by using PropertyDrawers. I indeed failed to translate any of my editor extensions to PropertyDrawers as soon as they were a little bit more complex. My personal impression is that they are useless in general. You can use them for very simple tasks and as soon as it gets just a little bit complicated, you are lost. I am a huge fan of the concept of PropertyDrawers, but it doesn’t feel production ready for me, unless you are working for Unity and you have the possibility to modify the source code of Unity directly in order to get something working.

You could use

with

to use

maybe this helps.

@Marrrk, that doesn’t work unfortunately. When the PropertyDrawer is for an array element, you are only getting the SerializedProperty of that array element and that is it.
I couldn’t believe it myself that this kind of basics can’t be achieved without ugly workarounds.

I thought that the SerializedProperty you get has a usable propertypath which can be used after modifications with the Find method, bad that this is not the case then.

Or i have to draw the whole array myself and add the text at the front of the property.
Then i know what index of the array I’m currently dealing with.
The problem is how to build an array inspector via the PropertyDrawer that looks and works like the default inspector.

1 Like