I’ve been working quite a bit on custom editor things lately, and the documentation is severly lacking. This is not only true for editor scripts, but that’s where I’ve noticed it the most since it’s where I’ve spent almost all my time recently.
Some examples:
Unity - Scripting API: PropertyDrawer → “Note that for performance reasons, EditorGUILayout functions are not usable with PropertyDrawers.”
But they do seem to work, at least for me, and based on a forum post probably for at least one other person as well.
Oh boy… this one… so many issues…
- .objectReferences → “Never returns null. If no object references are available returns an empty array.”. Sounds good, the standard .NET way of never returning null for collections. It also hints (a lot) that it’s ok to not set that field to anything, especially since there’s a “SetGenericData” function available. This is not the case, and it was very hard to figure out why since Unity didn’t inform me in any way whatsoever. It simply stopped / never began to fire DragUpdate and/or DragPerform evernts. I was lucky enough to find a single sentence in a thread from 2013 about this issues, Editor DragAndDrop bug - system needs to be initialized by Unity? - Unity Engine - Unity Discussions → “Oh, I also set a “new object[ ] { null }” in the objectReferences fields. Maybe it has something to do with it. Sorry… 3 AM.”. A lot of hours wasted because of either a bug in how the DragAndDrop class works or due to poor documentation. Further down in the thread someone posts, “So my guess is, Unity at some point try to test or to marshal “objectReferences” and get an invalid pointer, and someone forget to throw an exception when that happen”.
- .visualMode → “The visual indication of the drag.” Right. Except, it does more than that. Just seeing a field called “visualMode” hints (again, a lot) about the usage; get / set the visual indication used when doing a drag operation. For some reason someone thought it’d be fun to also have the .Rejected and .None modes actually affect how the DragAndDrop behaves. I can accept that (although I think the name of the field isn’t good if the field affects behaviour), since visual mode can be interpreted in a different way, but if that’s the case the documentation for the visual mode enum should state that. Clearly.
- .SetGenericData() → Not the best of names since it doesn’t work with generic data.
- And better examples would be nice. Maybe not needed if the issues listed is taken cared of, but hrms.
There are a lot of places where the documentation for fields and functions is “incomplete”. A typical example I found today when trying to learn about SerializedProperty. A serialized property has a function called ClearArray(). Kind of obvious what that function does, right? I mean, I’d guess that it “clears” the array, emptying it, removing all the elements from the array and so on. The description even says so in case it wasn’t obvious enough, “Remove all elements from the array.”. However, seeing such a description among the first public functions listed on a SerializedProperty (which has a ton of fields and quite a few functions) kind of doesn’t say much. Sure, it clears the array, but what array? I had to click on the function name to get to the page dedicated for the function, where I saw “See Also: isArray.”. After clicking on that link I understood “what array” it was that was being cleared when calling the function.
Now, the last part isn’t a major thing in itself, but the same issue keeps coming up over and over, and it’s often easily fixed. In this particular adding something along the line of “… when the serialized property is an array.” would’ve made it so much more clear.
There. Can’t sit around complaining to myself if I’m not trying to do something about it. Again, apart from the specific DragAndDrop stuff I’d just like an overhaul. I understand it costs time and money and all that, it’s fine. But please, do have a look at the DragAndDrop class (either the code or the documentation, because they are severly misaligned and / or not working as intended).