How can I Select/focus the SceneView in Editor?

Hi,

How can I Select/focus the SceneView in Editor?

I want to focus automatically on the Sceneview when clicking a button in my custom InspectorGUI.

But i can't find an solution to that ... can anybody help me with that?

Unfortunately the SceneView class is not documented. If you use Microsoft Visual C# you have IntelliSense which gives you all you need. `SceneView.sceneViews` is an static ArrayList that contains all open SceneViews (keep in mind there can be more than one). SceneView inherits from EditorWindow so every SceneView have a `Focus()` function like Elliot said. To focus the first available SceneView do something like:

// JS
if (SceneView.sceneViews.Count > 0)
{
    var sceneView : SceneView = SceneView.sceneViews[0];
    sceneView.Focus();
}

// C#
if (SceneView.sceneViews.Count > 0)
{
    SceneView sceneView = (SceneView)SceneView.sceneViews[0];
    sceneView.Focus();
}

Use EditorWindow.Focus.

I did this:

using UnityEditor;
using UnityEngine;
    
internal sealed class SceneViewFocus : EditorWindow
{
    [MenuItem("Utilities/SceneView Focus")]
    private static void OnStartup() =>
            
        _ = GetWindow<SceneViewFocus>(utility: true, title: "SceneView Focus", focus: true);
        
    private void OnGUI()
    {
        // NOTE: This will focus on the first opened SceneView instance found
        if (GUILayout.Button("Focus on SceneView Window"))
            FocusWindowIfItsOpen<SceneView>();
            
        // If you wish to open the Window then focus (in case it's closed), do this instead:
        /// <![CDATA[
        /// GetWindow<SceneView>().Focus();
        /// ]]>
    }
}