@HideInInspector

I was studying Eric’s 2D shooter he posted the other day - thanks Eric for that, it’s a great learning tool. I have a question:

What is the difference between declaring a variable private and using the statement @HideInInspector?

I use private quite a bit, but never came across @HideInInspector.

Thanks for any info.

Mitch

If you declare a variable private, then it can’t be accessed from other scripts. Sometimes I needed the variable to be public, but didn’t want it to be visible in the Inspector, since there was no reason to set the value there in those cases.

–Eric

Ah!

That makes sense. Thank you.

Hope this is an easy one. Is there a way to make a variable available to other scripts but hidden to the inspector as with

@HideInInspector()
var p = 5;

in javascript?

Also, does the line above apply only to the variable beneath it? i.e. can I do something like

@HideInInspector()
{
var a = 1;
var b = 2;
}

I don’t use C#. :wink: You can’t use @HideInInspector in C# anyway. Take the () out:

@HideInInspector
var p = 5;

As far as I know, yes, you can only do one line at a time.

–Eric

Just to clarify, in C# you use

[HideInInspector]
public string StringToHide;
static var someVariable : int

allows you to access it in other scripts but not be shown in the inspector. great when used in conjunction with a singleton.

cheers.

That is a class variable, you have to access it using the Class name and not an instance, that is why its not shown in the inspector, if the use of that variable is dependent of the intance (i.e. lifetime of an object) then static is not the way to go since it will hold one value at the time… is a class variable :smile:

.org

Many, many blessings on all your camels- no blessings on ALL your livestock! Unity has become a much cleaner place to exist. Thanks again, this is superb!