Search Issue Tracker
By Design
Votes
2
Found in
4.5.2f1
Issue ID
623951
Regression
No
[SelectionBase] attribute on parent GameObject does nothing when prefab child exists
To reproduce:
1) Make two gameObjects and give them a child which you can click in sceneview easily, for example, Sphere
2) Make one of those Spheres a prefab
3) Create a script and add SelectionBase attribute
4) Attach script to each parent
5) Select each object from scene view. When object with no prefab is selected, the parent highlights in hierarchy. When object with child prefab is selected, the child is highlighted in hierarchy
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Only the left screen is rendering when using Render Graph Fullscreen Blit in Meta Quest 2
- Context menu with the "Revert" option doesn't appear when pressing the right mouse button on a "Vector2" or "Vector3" property in the Inspector of a custom shader
- Missing Render Feature "Full Screen Pass Render Feature" in any “Universal Renderer Data” asset when upgrading from 2022.3
- Inconsistent ParticleSystemVertexStream.PercentageAlongTrail data range in Trail Texture Modes except "Stretch"
- The Graph Debug Window can be right clicked through and the Node Workspace is manipulated instead
Ledii
Sep 08, 2024 03:23
For those who miss this functionallity, this was a sufficient replacement for my purpose.
private Transform PreviousTarget { get; set; }
private void OnDrawGizmos()
{
ForceSelectParentFirst();
}
private void ForceSelectParentFirst()
{
var children = transform.GetComponentsInChildren<Transform>(true).ToList();
var target = Selection.activeTransform;
if (!children.Contains(PreviousTarget))
{
if (children.Contains(target) && target != transform)
{
Selection.activeTransform = transform;
}
}
PreviousTarget = target;
}
xtyler
Apr 16, 2022 17:00
Voting with a comment - please reconsider changing the design! The intent and use case of this feature is to override default selection rules, and fixing this could not hurt existing uses/workflows.
Recky
Dec 13, 2021 11:55
Fix it, please!
GrandBOOM
Sep 01, 2021 12:49
If this is "by design" then the design should change.
As many have pointed out. This is stupid. Just fix it. Give us an ability to add an Int or a simple Enum to the selection base attribute that decides what object has priority.
hyperdivegames
May 24, 2021 15:13
Hey there, I was having the same issue and found two ways to solve this. I coded a solution but after coding it I found a reason for this not to be working on the first place.
1rs solution:
I had a big plane crossing all objects. So first selection would go to that plane, second would go inside the prefabs (as it was identified as a "finer" click, since I already had something selected). I've just turn off the "pickability" (as pointed by GARDENFIENDGAMES) of this big plane and the SelectionBase attribute started working again as intended. Notice that this plane doesn't have to have any hierarchical relations with the prefab that you are trying to click to mess up the picking.
2nd solution:
If you still haven't solved the problem or want to keep the "your plane" clickable, you can copy this code into a Editor folder. Just bare in mind that you won't be able to select neither children nor parents of the object with a SelectionBase component through the SceneView, only through Hierarchy.
using UnityEditor;
using UnityEngine;
using System;
[InitializeOnLoad]
public class HyperSceneViewTools : Editor
{
static HyperSceneViewTools()
{
SceneView.duringSceneGui += UpdateView;
test = false;
}
static bool test;
static Transform selectedTransform;
private static void UpdateView(SceneView sceneView)
{
HyperSelectionBase();
}
static void HyperSelectionBase()
{
if (Event.current != null)
{
if (Event.current.type == EventType.MouseDown)
{
test = true;
selectedTransform = Selection.activeTransform;
}
}
if (test && Selection.activeTransform != selectedTransform)
{
test = false;
if (DifferentSelectionBase(Selection.activeTransform, out Transform selectionBaseTransform))
{
Selection.activeTransform = selectionBaseTransform;
}
}
}
static bool DifferentSelectionBase(Transform transform, out Transform selectionBaseTransform)
{
if (transform == null || IsTransformASelectionBase(transform))
{
selectionBaseTransform = transform;
return false;
}
selectionBaseTransform = transform.parent;
while (selectionBaseTransform != null)
{
if (IsTransformASelectionBase(selectionBaseTransform))
break;
else
selectionBaseTransform = selectionBaseTransform.parent;
}
if (selectionBaseTransform != null)
return true;
else
{
foreach (Transform child in transform.GetChildrenTransformOrderByDepth())
{
if (IsTransformASelectionBase(child))
{
selectedTransform = child;
return true;
}
}
}
selectedTransform = null;
return false;
}
static bool IsTransformASelectionBase(Transform transform)
{
foreach (Component component in transform.GetComponents<Component>())
{
if ((SelectionBaseAttribute)Attribute.GetCustomAttribute(component.GetType(), typeof(SelectionBaseAttribute)) != null)
return true;
}
return false;
}
}
GardenfiendGames
Feb 22, 2021 22:15
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 gamobject in Scene View and it selecting the root prefab container.
whilefun
Jun 30, 2020 19:19
This is still "working as designed" in v2019.2.x :|
It's a real pain, especially given the new prefab workflow.
zorkwarrior
Mar 30, 2019 16:57
How is the blanket statement "by design" applied here? It says in the API:
" You can make other objects be treated as selection base too. You need to create a script class with the SelectionBase attribute, and then you need to add that script to the GameObject."
Well I did and it doesn't work. Is this supposed to not work "by design"?
My case is that I have an empty gameobject with a script (that is a prefab and marked with [SelectionBase]) and a UI.button as a child
StunAustralia
Aug 04, 2018 14:38
With the upcoming nested-prefabs this designed behaviour will become even more undesirable.
Essentially, there will be no point marking anything (including a "master prefab" that contains nested prefabs) as [SelectionBase] because selecting any of it's prefab children will lock the selection to them rather than bubbling up.
I know it's by design.
I vote for change regardless.
Candescence
Jul 04, 2018 06:58
I'm also going to have to concur with Xarbrough and Stardog, it doesn't make sense that it's "by design", because it completely defeats the point of the attribute and makes it useless.
It's extremely frustrating when I want to level design with modular parts based around a root empty gameobject and I have to keep manually selecting the root gameobject in the hierarchy while still keeping my objects organized under another gameobject so my hierarchy isn't a complete mess.