Scene pivot not updating on middle mouse click

Using Unity 2022.3.14f1
it looks like tapping middle mouse button anywhere no longer works to switch the scene pivot point.
-IT’S NOT MY MOUSE- My mouse works perfectly fine in and outside of unity, I can still press and hold middle mouse to drag the scene view around.
I tried creating a new clean project, thinking maybe it’s some package I had on my original project but it’s the same issue.

This means I’m not able to work on fine details in maps, and scrolling once makes a huge leap in distance, and even nearby objects are clipping before the camera gets near.

I’m wondering if there’s an alternative way to switch the scene pivot other than just middle click, or maybe a toggle to fix that in editor preferences?

I usually just select an object and press F to focus, or else perhaps click on terrain, both of which should reset the scene pivot… do those still work? If not, try reimporting all…

1 Like

yeah, I’ve been getting around pressing F to focus on a game object of smaller sizes, my scenes currently don’t have any terrains, but even so, this also happens in fresh new projects, so it’s not just the current project I’m working on.

I’m mostly curious if this is a 2022.3.14f1 issue (since I wasn’t having that issue on previous versions), or if something went wrong in my installation, or if it’s just not a feature anymore in that version.

I guess my question for everyone is if this is something that’s not working in 2022.3.14f1 or if my own version is flakey and I need to reinstall or do something else.

I am using 2023.2.1f1 and have the same issue.
when I use 2021 LTS it is fine I did not test with 2022 however

So in 2021 LTS, holding Middle Mouse temporarily switches to the Hand tool. This allows you to drag to pan the scene viewpoint around.

In 2022.3.14f1, holding Middle Mouse does not always automatically switch to the Hand tool. If you manually click the Hand tool, then you can drag and pan the scene. They broke it.

It seems like if you use any window other than the Scene view, then your Middle Mouse will just not work at all (even if the Hand tool is selected), until you specifically give the Scene view focus again. This is really a bad workflow snag. I don’t want to click on stuff in the Scene, thus messing up whatever I already have selected. I just want to move the scene viewpoint around. If I am in 2D mode, I can’t just Right Click to go to WASD Fly mode, like I could in 3D.

So it’s definitely not just something bad with my installation, but something that’s affecting everyone with those versions… On one hand, I’m glad to know it’s not just me, on the other hand, it’s worse…
I really hope this gets fixed soon, it’s so annoying having to click and object and tap F, it’s also very inconsistent.

Yeah, it’s a crappy turn of events. After further experimentation:

The mouse wheel will zoom your camera whether the Scene view has focus or not. This is true in all modern versions. You just have to have the mouse cursor within the Scene view area.

In 2021 LTS, the middle mouse click (while the cursor is in the Scene view area) will switch focus to the Scene view, and grab your camera for panning if you hold and begin to drag the mouse.

In 2022 LTS, the middle mouse click will NOT switch focus to the Scene view, and will NOT grab your camera when the Scene view does not currently have focus. A functionality regression.

You can left- or right-click the Scene tab itself to put it into focus, so that the middle mouse panning can work. An annoying extra click, but it doesn’t upset the selection or anything else.

If your Scene view has the gray toolbar across the top (showing docked overlays like Pivot, Local, Grid, Magnet, and the various View Options like Render Mode, Lighting, Gizmo Toggle, etc.) then you can left- or right-click in that gray toolbar area to put the Scene view into focus. An annoying extra click, but it doesn’t upset the selection or anything else.

1 Like

It’s really annoying. But since it is a general problem, it will probably be fixed in future updates.

I also noticed this in 2022.3.14f1. I can’t speak for other versions of 2022 since this is my first attempt at using it, but I really miss the middle mouse button press as a re-pivot. Is it possible to manually reset this anywhere?

Just updated to 2022.3.14f1 and this bugged the hell out of me since I use the pivot constantly. I decided to go on a short procrastination adventure and implemented a workaround:

using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public class SceneViewPivot {

    private static bool _setPivotOnMouseUp;

    static SceneViewPivot() {
        SceneView.duringSceneGui += OnSceneGUI;
    }

    private static void OnSceneGUI(SceneView sceneView) {
        Event e = Event.current;

        if (e.type == EventType.MouseDown) {
            _setPivotOnMouseUp = (e.button == 2);
        } else if (e.type == EventType.MouseDrag) {
            _setPivotOnMouseUp = false;
        } else if (e.type == EventType.MouseUp && _setPivotOnMouseUp) {
            UpdatePivot(sceneView, e.mousePosition);
            _setPivotOnMouseUp = false;
        }
    }

    private static void UpdatePivot(SceneView sceneView, Vector2 mousePosition) {
        Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hitInfo)) {
            sceneView.pivot = hitInfo.point;
            sceneView.size = (hitInfo.distance / 2.0f);
        }
    }
}

This snaps instantly to the new pivot position instead of interpolating nicely like normal, but its better than nothing!

5 Likes

You are awesome! This will definitely save me some frustrations!

1 Like

Thanks a lot! Needed this, because I’ve larger objects (like meshes along a path) and focusing them just sets the scene view pivot to the center of the object. That doesn’t help. I need to be able to set the scene view pivot manually. Great work. Don’t get, why this feature disappeared in the first place.

1 Like

Hi there!
I certainly hope you don’t mind, but I have taken your code and run it through the fun ChatGPT thing to get interpolation working. See below. It has the added bonus of being able to change the value of the “interpolationSpeed” value to change how quickly it snaps to the new pivot point.

Thank you so much for your code - I hope this works well for you as it has for me, seeing as it seems to restore an apparently lost function in this version of Unity. It’s been a remarkable resource for me and an incredible help. I wouldn’t have this working if it wasn’t for you, so… Thanks again.

Edit: Would have to wait for interpolation to complete before being allowed to move the scene view again. Fixed this by stopping the interpolation during other OnSceneGUI events if the camera is already interpolating. Silly ChatGPT (And Silly me… I got excited to reply to this without doing enough testing).

Note: This doesn’t work as well as the inbuilt way that this function works. This will ignore some models in the scene - I am unsure if it ignores custom meshes or what, I don’t really ever mess with editor scripts.

using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public class SceneViewPivot
{
    private static bool _setPivotOnMouseUp;
    private static Vector3 targetPivot;
    private static float interpolationSpeed = 0.1f; // Adjust the speed as needed
    private static float interpolationStartTime;
    private static bool isInterpolating;

    static SceneViewPivot()
    {
        SceneView.duringSceneGui += OnSceneGUI;
        EditorApplication.update += Update;
    }

    private static void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        if (e.type == EventType.MouseDown){
            _setPivotOnMouseUp = (e.button == 2);

            if(isInterpolating){
                StopInterpolation();
            }
        }
        else if (e.type == EventType.MouseDrag){
            _setPivotOnMouseUp = false;

            if(isInterpolating){
                StopInterpolation();
            }
        }
        else if (e.type == EventType.MouseUp && _setPivotOnMouseUp){
            targetPivot = CalculatePivot(sceneView, e.mousePosition);

            interpolationStartTime = (float)EditorApplication.timeSinceStartup;
            isInterpolating = true;

            _setPivotOnMouseUp = false;
        }
    }

    private static void Update()
    {
        if (isInterpolating){
            SceneView sceneView = SceneView.lastActiveSceneView;

            if (sceneView != null){
                float distanceThreshold = 0.01f; // Adjust the threshold as needed

                // Check if the distance between current pivot and target pivot is below the threshold
                if (Vector3.Distance(sceneView.pivot, targetPivot) < distanceThreshold){
                    StopInterpolation();
                    return;
                }

                if (EditorApplication.timeSinceStartup - interpolationStartTime < 1f / interpolationSpeed){
                    // Calculate interpolation percentage
                    float t = (float)(EditorApplication.timeSinceStartup - interpolationStartTime) * interpolationSpeed;
                    // Smoothly interpolate the pivot towards the target pivot
                    sceneView.pivot = Vector3.Lerp(sceneView.pivot, targetPivot, t);
                }
                else{
                    // Reset the interpolation flag when the interpolation is complete
                    StopInterpolation();
                }
            }
            else{
                // Reset the interpolation flag if there is no active SceneView
                StopInterpolation();
            }
        }
    }

    private static void StopInterpolation()
    {
        isInterpolating = false;
    }

    private static Vector3 CalculatePivot(SceneView sceneView, Vector2 mousePosition)
    {
        Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition);
        if (Physics.Raycast(ray, out RaycastHit hitInfo)){
            return hitInfo.point;
        }
        return sceneView.pivot; // Return the current pivot if no intersection is found
    }
}
2 Likes

Thanks for the script! It prevents making successful builds, but it’s as simple as commenting it out before making a build.
I REALLY hope that Unity gets it together and fixes it by next update, I first noticed it on 2022.3.14 (if I recall correctly, it wasn’t an issue in 13), I’m in 2022.3.16, still an issue.

Interesting that it causes you to not be able to make a build! I made a build with it just fine, so I have literally no clue what might be going on there.

I think it was related to wanting to execute editor code for a build, I’ll have to revisit that again when I try my next build, but if it was that simple, I guess an “if editor” should help fix that issue

if only we were so lucky… still happening in 2022.3.31 for me