Finding what editor window is focused c#

Hi, I am making a custom editor window for a project and I am trying to get the currently focused editor window to see if its either an inspector window or the scene window.

I have been using

if (EditorWindow.focusedWindow.title == "Inspector")
{
     do something here
}

however in unity it throughs a warning

warning CS0618: 'EditorWindow.title' is obsolete: 'Use titleContent instead (it supports setting a title icon as well).'

it works as expected however I would
1.Prefer to change over to titleContent, however the docs are non existant and all other searches for this return how to set the title and icon and not how to get and compare.
2.Stop the message showing as the functionality works as expected (why break something if it works… just dont know for how long it will work though)
3. A different way to find and compare the focused window?

You either use reflection (since most of the built-in windows are internal or use string comparison:

UnityEditor.EditorWindow.focusedWindow.ToString() == "Something"

If you Debug.Log out the focusedWindow.ToString() and you click through all the windows you can explore what they give you back. Usually the namespace like UnityEditor.SceneHierarchyWindow.

1 Like

Thank you @ that fixed the issue!