Lock in Inspector?

Is there a way to lock a specific variable just like hiding it with [HideInInspector]?

I still want to see it in Unity but not be able to change it.

if you want to see that for debugging i suggest to use the debug mode

All you need to do is chech the view from normal to debug with the gear in the top right angle of the inspector window
In this way you can view all the private variables

The variables still need to be public so other Scripts can access them.

They don’t have to be. Wrap them in a public read-only property.

private float myFloat;
public float MyFloat { get { return myFloat; } }

Or if you’re compiling on the 4.6 runtime

private float myFloat;
public float MyFloat => myFloat;
1 Like

You can create your own “ReadOnly” attribute.

Then decorate your variables with “[ReadOnly()]” to prevent modification of the variables in the inspector.

Example:

[ReadOnly()] public int x;
2 Likes