Why Unity developers don't open up most of their internal EditorGui stuff?

before I even start another one of my anger frenzies, take a look at this picture :

It looks simple isn’t it? you are dead wrong, did you ever tried to have the same search bar unity has in project window, hierarchy view and many more places in your own custom scripts?
you want to see what it takes to make it happen? The code sits as an internal static method inside EditorGui class, the name? ToolbarSeachField !!! Wow seriously, why i have to do all of this to have this handy thing in my custom editors? take a look at the code :

First we need to get the proper method, that method had 3 overloads !

private static void GetWantedMethod()
        {
            var methods =
                typeof (EditorGUI).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                              BindingFlags.Static);
            foreach (var method in methods)
            {
                if (method.Name == "ToolbarSearchField" &&
                    method.GetParameters()[0].ParameterType == typeof (int) &&
                    method.GetParameters()[1].ParameterType == typeof (Rect) &&
                    method.GetParameters()[2].ParameterType == typeof (string) &&
                    method.GetParameters()[3].ParameterType == typeof (bool))
                {
                    wantedMethod = method;
                    break;
                }
            }
        }

then i had to invoke this method with proper parameters to get the job done, for what? for getting a nice fancy contoll that is sitting inside unity’s built in system, but for some stupid reason, they decided to keep it for themselves or totally forgot that it can be made public and used for places other than filtering their window content !!!

And that is the tip of iceburge, Unity has tons of built in gui styles, that could be handy for anyone if they made it public in a single static class as constants !!! Wow, really thank you guys. I have to go for reflection to have these things that make unity really flexible when it comes to it’s editor?

WHY?

Your picture doesn’t work…

Also, yeah, there are a lot.

I usually keep a decompiler on hand to search around for what’s in there.

You can never be sure why they don’t make them public. But it might be because they don’t know if they’re in a final state. They might change in the future. Once they make them public, they need to be supported for the public, which makes change harder (i.e. GetComponent fiasco coming to Unity5).

When they’re internal, if they want to make ToolbarSearchField work completely differently, the only have to get the internal dev team up to scruff on the change.

So yeah, when accessing those methods, be sure to understand, they could change and break at any moment on upgrade.

With that said, I use a special wrapper class for this:

You can see in my ‘SPEditorGUI’ class I use it to uncover those methods:

        public static float GetSinglePropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (_imp_GetSinglePropertyHeight == null) _imp_GetSinglePropertyHeight = _accessWrapper.GetStaticMethod("GetSinglePropertyHeight", typeof(System.Func<SerializedProperty, GUIContent, float>)) as System.Func<SerializedProperty, GUIContent, float>;
            return _imp_GetSinglePropertyHeight(property, label);
        }

...

        internal static Rect MultiFieldPrefixLabel(Rect totalPosition, int id, GUIContent label, int columns)
        {
            if (_imp_MultiFieldPrefixLabel == null) _imp_MultiFieldPrefixLabel = _accessWrapper.GetStaticMethod("MultiFieldPrefixLabel", typeof(System.Func<Rect, int, GUIContent, int, Rect>)) as System.Func<Rect, int, GUIContent, int, Rect>;
            return _imp_MultiFieldPrefixLabel(totalPosition, id, label, columns);
        }

I use it in other places as well.

Pretty much the entirity of com.spacepuppyeditor.Internal:

Primarily as a means to implement my own editor scripting environment that allows for things like: multiple PropertyDrawer attributes on a field, allowing a PropertyDrawer to handle an entire array rather than applied to each individual element, and other stuff.

1 Like

picture issue is not my fault, they are uploaded on imgur.
about keeping these things internal, well, the only job of something like the searchtoolbar is to return a string while it has a little button to clean the text area, nothing big there to be changed in future, but people who don’t know reflection enough would need to capture the screen to extract parts of the gui like the magnify icon, then the right curve side and then the text field itself, then pull their hair to put 3 elements in such a way that they look like a single one when the whole thing is already done once by unity team. also, letting us getting access to stuff like gui styles that they use internally shouldn’t break anything, after all gui styles are just eye candy stuff and when they change something internally, the whole look of unity would change and most likely you would want to keep your window fit in the same theme.
I am not asking them why they don’t open doors for dangerous things, all i want to know is why they are not opening the gates to editorgui controllers that they are using for ages now.

not on the priority list…

See, to put something public isn’t just a matter of marking it ‘public’. It requires testing, documentaiton, support, management approval, etc.

Lets say dev gets from design the need for a search tool. So they write one up, they show it, and some headup says “good enough, put it in. We might return to this later though.”

Dev then puts it into production, wires it up to work in the 4 or 5 places its needed. And moves on with business… they have a long list of features that need to get done. It’s marked internal because no one has really tested it outside of the handful of use cases… and who knows, we might want to change this in the future.

Wait, wait, why didn’t they just mark it public then? Well… that’s not so easy. That would require testing it in the 4 or 5 places it’s used. But instead running a set of unit tests on it throwing a barrage of use scenarios making sure it handles all of them. If any of them fail, fixing the issue that results, and retesting. Furthermore, now the method enters live support. Again… it’s not just the 4 or 5 places its used by internal dev, this is the infinite realm of possibilities found out in the wild. This means extra work by QA with every future release… sure it’s small, but it’s there, and they add up. All of this may only account for a possible 30 minutes extra work. But lead says… “screw that, you have other stuff to work on today… push it into production and continue on… deadlines! If we decide to make it public in the future, we can then.”

Time passes, and well, they never return to it. Stuff to do, other projects to work on. It’s determined that it works just fine in production, no reason to change what works fine. But it’s still marked internal because when originally created they never bothered to go that extra step.

Now it’s 3 years later, and it still hasn’t been brought public.

Someone decides, lets make this public.

OK… well what needs to be done to do that? Just mark it public? NO!

  1. someone needs to decide to do it! Why? Who is pressuring for it? Why this method and not any of the 100’s of others?
  2. we need to run that unit test on it, and fix any issues that come with it.
  3. ope! There were errors in the unit test… fixes made… crap, now we need to run a barrage of QA testing on the editor to make sure that the 4 or 5 places we use it internally still work correctly
  4. damn, broke the editor, gotta fix that
  5. back to QA
  6. now it needs to be documented…
    (keep in mind, this might span across departments, a cycle in QA might be on next build tomorrow morning, that 10 minute job just turned 48 hrs)

But then wait… why this function? Why just this single function? Why not the 100’s others that piled up over the years?

So OK, we have to take the time to do all that as well.

This takes time away from the primary features they’re working on though. At minimum you have a dev taking on role of dev/test/doc, or possibly more employees if you divide that work. Who could easily be working on other more pertinent tasks.

But this is important… but why?

Cause a couple of users want it. Despite the fact that the majority of users don’t even bother writing advanced editor scripts. Then there’s a minority who do, who often rely on 3rd party assets to do so developed by smart people who DO know how to reflect out the necessary tools, or write their own implementations. Or the even smaller minority of users who are small studios that have an engineer who most certainly knows how to do this.

Leaving the ultra small minority of tinkerers, like yourself, who also have the smarts enough to reflect out the stuff if they so desperately need it.

It’s a cost analysis. They have more important things to do then focus their resources on uncovering features that the majority of users haven’t really needed.

And that’s how most dev goes.

I used to work on a very large piece of software, like how big unity is, before opening my studio.

And that was my job… deciding what things inside the HUGE piece of software needed focus, and which could be put off. And it all focused on deadlines, and what the majority of our users wanted.

Sure, it sucks… but it’s not like its locked away. You can get at it. It just took a little extra work on your part.

3 Likes

you perfectly make sense lord, I have nothing to argue back with you :smile: that is the very first time someone knock me off this fast lol, meh one of these days i will sit down and right a piece of code that will generate a gui skin with all the internal custom styles being in it, am i correct in assuming that if people don’t use parts of that skin, the building of the game will drop those parts? or will they be included in the project? also, had the same question about editor folder under the resources folder, i know it’s totally off topic, but those two questions are bothering me for quit some time now.
By the way, thanks for all the time you put for that post, it was really eye opening.

If the code you write is included as runtime available code (not editor scripts), then it will always be included in the build.

If you write code the exists in an ‘Editor’ folder, it’s only used at editor time, and is not included in the build.

Things like ‘EditorGUI’ are only available in editor scripts, so you’d have to write it as an editor script, so no… it won’t be included. If you’re trying to make any of the skins available only via reflection, and make them available at runtime… your code WILL be included, but there’s no guarantee that the distributed dll’s from unity that you’re reflecting will contain the skins you reflect out. And since it’s internal, it’s undocumented, so there’s no real way to know with out just building and testing.

It’s reasonable to assume that a skin that unity uses only at editor time wouldn’t be included in the distribution, because it’s not needed then.

no no
let me explain. I am developing a node based editor, here is the folder structure :
—Resources
-------Database <---- this folder will contain scriptable object that is the node graph with nodes as it’s children
------------Editor <— this folder will contain another set of scriptable objects that relate themselves to the top level, these are only some variables needed for drawing the node in the editor, like rects, etc.
What i want is to find a way to drop everything under that Editor folder at build time without a need to write my own pipeline process or without running another menu command to destroy the objects in that sub folder because lets face it, after long time of game development, users will completely forget to delete such a folder before building the game.

another story is that reflected skins, what i was thinking was to get the gui styles from reflection but making a deep copy of them and put them in a gui style and save that gui style on the hard drive as another asset.

it’s really confusing me the way documentation is talking. it ways everything in the resources folder and it’s sub directories will be added to final build even if they are not currently used. well, those scriptable objects in the editor folder themselves have some calls to editor stuff but at the end they are scriptable objects.

on the other hand it says Editor folders will never include in final built. it confuses me, what will happen in this particular scenario?

Awww, you’re talking about a Resources folder that contains an Editor folder. And the conflict of information about a ‘Editor’ being neglected, but all ‘Resources’ being added.

Honestly… I don’t know.

Though really, I wouldn’t put code or editor stuff in my Resources folder at all. I’d structure more like:

MyPackage
-->Resources
------>Any textures/models/prefabs that are resources for this package
-->Code
------>Code for this package
-->Editor
------->All things Editor

so you suggest that i take out the editor folder out of the resources and put it beside it in the same level of structure. that can work, at least then we would be sure it will be dropped no matter what.