Search Issue Tracker

Fixed

Fixed in 2022.2.4f1, 2023.1.0a22

Votes

0

Found in

2022.2.0b10

2023.1.0a13

Issue ID

UUM-17445

Regression

Yes

GameObject is selected in the Scene view when clicked on, even though there is code preventing that

--

-

Steps to reproduce:
1. Open the user’s attached project
2. Open the “Assets/Scene_Bug.unity“ Scene
3. In the Scene view select the “Cube” GameObject
4. Try selecting the “Plane” GameObject

Expected result: The Cube GameObject stays selected
Actual result: The Plane GameObject gets selected

Reproducible with: 2022.2.0a4, 2022.2.0b10, 2023.1.0a13
Not reproducible with: 2020.3.40f1, 2021.3.12f1, 2022.1.18f1, 2022.2.0a3

Reproducible on: Windows 10

Notes:
1. Holding Shift when trying to select the “Plane” GameObject results in the correct behavior in 2022.2.0a4 and above
2. Look at the attached videos for clarity

3. User comment from ERTemplateEditor script:

??The below line has always worked in previous Unity versions. We use something like this in different ways in Asset Store tools to keep the current game object selected and perform tasks/processes when specific other child objects in the scene are clicked. In this case, after clicking the plane on MouseUp the Cube is deselected and OnSceneGUI is no longer called, it breaks the tool workflow. But when for example keeping the Shift key pressed and clicking the plane, OnSceneGUI() does run and the cube will remain selected. In previous versions it was not necessary to press the Shift key to keep the same game object selected.  And the Shift key already is used for specific processes so this workaround is not an option.??

  1. Resolution Note (fix version 2023.1.0a22):

    I reverted the change that caused the OnSceneGUI event to exit early after a selection change, restoring the behaviour of previous Unity versions.

    However, I would not recommend this method of preventing selection changes in the scene view. A more efficient way would be to register a default control to prevent picking from allowing any selection change in the first place.

    Example:

    using UnityEngine;
    using UnityEditor;

    [CustomEditor(typeof(templateScript))]
    public class ERTemplateEditor : Editor
    {
    void OnSceneGUI()
    {
    InterceptPicking();
    }

    // Example code showing how to prevent selection changes from clicking in the Scene View with an object selected.
    static void InterceptPicking()
    {
    var evt = Event.current;
    var id = GUIUtility.GetControlID(FocusType.Passive);

    switch (evt.type)
    {
    case EventType.Layout:
    // If the event is left mouse button and no navigation key modifiers are pressed, add a default control.
    // A default control will let any handles or ui in the scene take priority, but if nothing is closer
    // it will be chosen as the active control. Since picking is also a default control but tested after
    // all user code, this gives us the chance to intercept the event.
    if(evt.button == 0 && !evt.alt)
    HandleUtility.AddDefaultControl(id);
    break;

    case EventType.MouseDown:
    if (HandleUtility.nearestControl == id)
    {
    evt.Use();
    GUIUtility.hotControl = id;
    }
    break;

    case EventType.MouseUp:
    if (GUIUtility.hotControl == id)
    {
    evt.Use();
    GUIUtility.hotControl = 0;
    }
    break;
    }
    }
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.