Invoke custom Inspector window without instance?

Hi all,

I just started playing with a custom editor and came across the need to show settings in the same vein as the Project Settings windows. In fact, that is exactly what I am trying to accomplish!

Assuming I have a class with all static members, I would like these members displayed in the Inspector when a users clicks Project Settings > My Extension Settings. However, all examples I find show how to write custom inspectors for scene objects, or how to create custom windows, which is all good, except it’s another extra window (or panel) that isn’t really needed. Is there any way I can just hijack the Inspector window and show my custom editor extension there?

Thanks and happy holidays,
Patrick

Can you store your settings in a ScriptableObject? They can have custom inspectors, too.

I would suggest doing what @TonyLi said and making a ScriptableObject or if it’s editor only ScriptableSingleton. If you really don’t want the user to see the object you can always just use HideFlags.

1 Like

Happy new year everyone, and thanks for the replies! Saving the data in a ScriptableObject or Singleton seems like a plan, thanks. That still leaves the question of how to show those settings inside the Inspector though?

When you create a ScriptableObject in your project you will be able to click on it and view all the data in the inspector.

As @BMayne writes, serializable fields in a ScriptableObject are visible in the inspector just like serializable fields in a MonoBehaviour are. If you don’t like the default inspector, you can write a custom inspector editor.

Thanks for your replies and apologies if I haven’t been entirely clear. The step that is missing for me is the “prettifying” of the whole shebang. Ideally I would show these fields when someone clicks a custom entry á la “Project Settings > My Extension Settings”, without changing the object selection (both in the hierarchy and the asset view).

Required Items:

  • Make ScriptableObject to store all your data in.
  • A pretty EditorWindow

Flow:

  • User opens the editor window (MenuItem)
  • User changes a value.
  • Find your ScriptableObject
  • You take the value and set the ScriptableObject instance to that value.
  • ScriptableObject will serialize itself and safe with your project.

When you select any of the Edit > Project Settings > xxx menu items, it does change the object selection. It selects the corresponding ScriptableObject. These are special ScriptableObjects that Unity keeps in the ProjectSettings folder, which sits next to the Assets folder in your project. You can add your own with a custom editor script:

using UnityEngine;
using UnityEditor;

public class MenuItems
{
    [MenuItem("Edit/Project Settings/My Extension Settings")]
    private static void NewMenuOption()
    {
        Selection.objects = new ScriptableObject[] { yourScriptableObject };
    }
}

“yourScriptableObject” is a reference to your asset. You could store an instance in the root of Assets. A lot of plugins do that. Although I’m not really a fan of the approach, it certainly works, and it’s simple.

Awesome, thanks so much both! I never even noticed that the standard settings also change the selection. Both seem like fun options to explort, thanks!