How can i hide variables from the inspector ?

Should i use [HideInInspector] or @HideInInspector ?

And how do i make it for a single var or many vars in a block ?
For example from a single var:

[HideInInspector]publicfloat x =3.0f;

But if i have many vars like:

int x = 0; int y = 0; int z = 0; How do i put all of them togeather under a block to be hided from the inspector ?

The first one for C# the second one for JS.

You can’t - each one has to be decorated individually.

2 Likes

However you can improve it a lil bit in terms of readability.

    [HideInInspector] public float f1, f2, f3, f4 = 0f;
    [HideInInspector] public float f5 = 2f, f6 = 1f;
5 Likes

declare variable as private.

whilst that does remove things from the inspector it’s not always an option, i.e. if you’re using editor scripts you need to keep the affected variables as public for them to be altered by the editor script but you might not want the game designers or whoever is using the component to manipulate those values directly.

does anyone know if there is a way to alter visual studio to follow this formatting? it insists on the var being below the decoration :rage:

out of the box now, but ReSharper lets you customize that setting,and i would have to assume some other extensions do as well

For that u can also use This method:

public class h : monobehavior {
        [Serializable]
        public class ff
        {
            public bool g;
        }
        public ff f;
}

Or

[Serializable]
public class ff
{
    public bool g;
}

public class h : monobehavior {
        public ff f;
}

You can add all the variables you want to hide in ff class that you want to hide. You can add more class like ff in a single script or create other script for it. Just remember to remove monobehavior and add [Serializable] above the class