TIP: Use [HideInInspector] to prevent public variables showing in inspector

Sometimes when making a variable public for class interactions it doesn’t make sense for it to be settable in the inspector - e.g we don’t want to be able to change the ball in play state there. To prevent this [HideInInspector] can be placed above the declaration.

[HideInInspector]
public bool inPlay = false;
3 Likes

Thanks for sharing this @Clem_Sutanimulli, there are some nice attributes that can be used in this way.

I personally would prefer better support for the use of class properties within Unity, it really erks me to have to expose fields in this way.

grrr… grumble grumble :slight_smile:

Nice share, yeah theres alot of handy attributes that can be set :slight_smile:
and there are some that need to be used with caution like the [ExecuteInEditMode]

@rob, you can still use getter and setter properties within Unity, I find it strange that theyre not used more to get a better habit instilled when learning. I know the public scope coupled with the inspector is easier to grasp initially…

1 Like

You can use them, but they dont appear in the inspector…

1 Like

yea, i did have a tinker with serialising, but its messy and confused the hell outta me at this early stage lol

1 Like

Privacy & Terms