- Home /
How to select prefab children in scene view
Hello,
I've been reading up on SelectionBase Attribute and how all prefabs have this so that you select the prefab root when selecting any of it's children. While this is handy in a lot of cases, it's downright annoying when trying to select individual objects that are a part of the prefab. Often times, I'll need to click 2 or 3 times to select the appropriate game object.
My question is this: is there a way to disable(even temporarily) this functionality in unity so that when I select an object, it selects the expected object rather than the root prefab object? I'd prefer to not have to add the selection base attribute to every object in the scene in order for them to be selected with a single click.
Thanks!
Not really. You have very little control over what clicking in the scene does. There's the [SelectionBase] attribute... and that's about it.
What you can do is to write scripts that run in the editor which selects based on other parameters. You'll need to have a static editor script set to [InitializeOnLoad], and a static constructor that hooks up an event to the SceneView.onSceneGUIDelegate event.
Then in that event, you can use Event.current.mousePosition to figure out what you're mousing over, and set that as Selection.activeObject.
It's cumbersome, but fairly powerful. We're using this to have the mouse wheel scroll through all objects we're mousing over, which is the most useful feature. Good luck, and feel free to ask questions.
Baste - interesting idea!
2 questions:
I often use the mouse wheel to zoom in and out the scene view. Being that you're using this for cycling through objects, how do you and your $$anonymous$$m zoom in and out?
Secondly, you mentioned that you're Selection.active equal to the object that you're mousing over [which i believe is a single game object]. If you're doing this, how are you deter$$anonymous$$ing ALL of the objects that the mouse is currently over. Is there an additional raycast, etc that happens so you can get all of them?
Thanks for your input - I've found it difficult to get feedback on this topic!
Rusty
Answer by GardenfiendGames · Feb 22, 2021 at 10:42 PM
If you have a similar situation like me, where you have nested prefabs and don't want to select the root-prefab, it may be helpful to know that you can Alt+Click the "pickability" (the hand/finger icon to the left of gameobjects in the Hierarchy) to make ONLY that gameobject un-selectable and not its children. I use a prefab container for all environment gameobjects in my scene, and just learned about this Alt+Click, which fixed the issue of me clicking on any environment gameobject in Scene View and it selecting the root prefab container.
Your answer
Follow this Question
Related Questions
Unable to select anything on the Scene window by clicking 2 Answers
Auto-Selecting something else in Scene-View? 0 Answers
How can I set a selection-sphere in the editor 1 Answer
Selecting objects in scene view with left mouse button always selects child object. 1 Answer
Unity Editor style selection in game 1 Answer