2017 Update on #Unity3d PropertyDrawers: Still broken, don’t use

I’m blogging this because I’m slightly tired of Reddit commenters claiming that I make sweeping statements about things in Unity that have been broken “for years” and can’t point to public descriptions of such. That I don’t – when such things aren’t public because most developers don’t have the time to write them up publically, instead sharing them at conferences and in pubs – write hours-long explanations with full debugger screencaps + source code to “prove” to them that I know what I’m talking about and that I’ve exhaustively dived into the Unity API + runtime only to give up after the amount of work becomes unbearable for fixing Unity’s closed source engine.

(Yes, I make sweeping statements. 10 years ago I used to submit detailed bugs to Unity, back when they cared, and could be bothered to take bug reports seriously. 5 years ago I used to write detailed explanations of what was broken in Unity, and why. But I grew tired of saying the same things repeatedly, and I couldn’t justify continuing to write this stuff up when it cost so much time. So I ended up accepting that there’s a lot of things that the Unity Developer community knows, and accepts, and everyone just shrugs and gets on with making their games … occasionally pausing to advise newcomer developers “Yeah, don’t do that. The API looks like it’ll do what you want, but Unity published it without testing it, and it’s broken. Or they broke it 5 versions ago and haven’t bothered to fix it. Or they only implemented half the methods” — etc. These are recurring problems with Unity specifically!)

ANYWAY … PropertyDrawers were launched with Unity 4.something, and were a great idea – something to workaround (but not fix) the bad core design of the Unity Custom Inspectors rendering system. But Unity staff launched them less-than-half implemented (they silently fail on Generics, they can’t use the official GUILayout API that Unity wants everyone to use, etc), and never went back and finished what they started.

It’s 2017. And … they still don’t work, in basic ways. e.g. I found a thread where someone explained that moving the Rect for layout inside OnGUI … silently corrupts the rendering. There’s no reason this should happen – I verified it myself – beyond “property drawers have more internal bugs, still”. But it does.

My challenge today: implement an editor area for using tickboxes to fill a bitmask.

(You need this because Unity has no support for passing Boolean values to a shader, and no support for passing custom structs – even though all GPUs have had this feature for (off the top of my head) 15+ years, and all game engines except Unity have had it a similar period of time. In order to pass a set of Booleans, you have to pack them into an Int. But Unity doesn’t support SetInt because they couldn’t be bothered to implement the method call in their API, so you have to pack into a Float, which is scary but works)

You can’t do it.

I got as far as rendering the tickboxes, and they can be enabled or disabled by keyboard – but Unity ahs written a custom-custom (twice customised) implementation of mouse handling for the ShaderPropertyDrawer that has a broken click handler. Normal PropertyDrawers seem to work, but this one doesn’t.

Moving the code into a custom Editor immediately worked: there was nothing wrong in my code, it was bugs in Unity :(.

TL;DR: don’t use PropertyDrawer in Unity, ever.

Leave a Reply

Your email address will not be published. Required fields are marked *