Hierarchy in editor

I have a public string so it shows up in the editor, but how could I make it so that this string shows up under a menu, so for example:

> Menu
   String

So the public string only shows up in the editor when I actually click on the black arrow next to the menu. Just like how the hierarchy works with parents and children. So I want the public string to be a child the menu ‘folder’

The inspector is there to simply allow editing of the variables of an instance. There’s no built-in functionality to somehow group member variables inside a class logically. However you can physically group several variables in a seperate serializable class.

// C#
[System.Serializable]
public class SomeData
{
    public string someString;
    public int someInt;
}

public class MyMonoBehaviour : MonoBehaviour
{
    public SomeData data;
}

That way your class MonoBehaviour will show a field “data” which can be expanded.

You can also nest classes to create a hierarchy. It’s also possible to make an array or List of a custom class. Just try it out.

You can use

[Header("Menu")]
public int myInt = 0;

This can be used to group variables together, but you won’t be able to collapse the data.

Here’s the unity link for reference Unity - Scripting API: HeaderAttribute

You can also use

[Space(10)]

If you want some extra space between variables