Variable private in inspector but public in other script.

Hello,

if I understood correctly I make a [SerializeField] public, if I want my variable to be editable in the inspector but remain private to other scripts.

Sorry if I’m wrong and misunderstand this feature.

What I would like to know is how to make a variable public (to be able to access it with another script) but private in the inspector (not to be able to access it from the inspector)

public means it is accessible to other scripts. If you don’t want it to be accessible it should be private.

A few options:

  • Make it a property. Unity doesn’t serialize properties by default public int MyProperty { get; set; }
  • Use [System.NonSerialized], e.g. [NonSerialized] public int MyVariable;
  • Use [UnityEngine.HideInInspector], e.g. [HideInInspector] public int MyVariable;
1 Like

If I understand you correctly, you want to use [SerializeField] private

Edit: Ignore this, I misread the question.

[HideInInspector] ```
is just perfect thank you, I know it but I had forgotten it, not easy to program, we spend our time relearning the same things, thank you very much ^^