Force select object in hierarchy via editor script?

Can you force an object as selected in the hierarchy editor view via an editor script?

I have an editor window script that collects some objects to give general warnings. I’d like to be able to force them as the selected objects in the hierarchy view for quick reference. Is that possible?

1 Answer

1

Yep, you certainly can. If I remember correctly, it’s all in the Selection class:

Yeah I had been looking at that doc but wasn't sure how it would take my reference to and add it to that list of selections. Do you just assign a new array of GameObjects to the Selection.gameObjects?

–

Even easier - you can just assign to Selection.activeGameObject. It's not read-only.

–