Thursday, September 24, 2020

Selected Objects Count in Unity

Another year, another dive into EditorWindows. A question at work about where to find a count of the currently selected objects in a scene lead me to make this one. Further inspired by the similar stats option found in 3DS Max and other modeling software I wanted this to be visible from the Scene window itself, not in a separate pop-up Editor Window.

Multiple questions I had when working on this (When do I use GUILayout? How to make a toggleable menu item? What can I do with SceneView?) were, in typical Unity fashion, poorly documented. Thankfully for Google and the braver, brighter Unity devs that already slogged through this this was a pretty quick tool to write up.

Count with me!

I'm mostly pleased with the final product - nice and simple! Select objects in the scene or hierarchy and a counter in the bottom left will be updated. The UI overlay can even be toggled ON/OFF in a menu item.

My only grief is that technically this counter doesn't count only scene objects - it counts any selected object in the Editor, including in the Project window. However, I didn't search out a way to filter these out as I could imagine someone having a use for counting objects in the Project window.

The full code is below or a Unity Package can be downloaded here. Either way, the script must be added to an Editor folder to work.

No comments:

Post a Comment