Is it ok to make all variables public in Unity?

In by John FrenchPublished

When you first start working with Unity, and especially if game development is new to you, you might find that a simple approach is to just make everything public, so that you can access it easily.

After all, you’re probably the only person that’s working on your game, so you know how everything is supposed to be used.

And, while your project is small, that may not be a problem.

However, the main issue with giving yourself access to everything is that, once you get into your project, you’re likely to forget how everything works.

Projects get big, fast, and even simple systems can be surprisingly complex.

As a result, it’s generally good practice to only make something public if it really needs to be, limiting a script’s functionality to a few essential exposed functions and values.

That way, even if you’re the only one working on your game, your scripts will be easier to understand and harder to break.

See also: