FindObjectsOfType only for base class, not derived classes

Do you have a nice method of emulating that? I’m in a situation where I only want an array that holds objects of the type I give it, not derived types. There’s a bunch of ways to achieve that result, but what’s the cleanliest? (C#)

there is no way aside of explicitely filtering the results you got for a request of the base type as all extended are base type too, aside of being also of the rest of the hierarchy I fear

Not an answer to the question, but I would avoid FindObjectsOfType altogether. It is extremely slow (and becomes slower with every object you add to the scene). I find that once levels reach there final size, the performance is so bad that even FindObjectsOfType calls used only in Start functions can lead to much longer loading times for your levels.

I personally switched to FindGameObjectsWithTag, which is much less convenient than FindObjectsOfType (due to having to make loads of tags), but it performs much better.

So why not use it in the Editor and serialize the variables?

Of course you can. It’s just that the strength of FindObjectsOfType is the convenience, which is kind of lost when you need to implement editor code for every class that uses it. I guess I prefer using tags over that.

Almost all of my scripts have an “Initialize” function. (Trying to order Start and Awake is just too complex.) I either need to call these functions from a script in the game, or I can put that same code in a menu item. Not everything can be done this way, like stuff based on screen resolution, but the Find-this-or-that, in my experience, can be taken care of very nicely in the Editor.