Public variable instead of SerializeField?

why not just define the variable as public instead of SerializeField?

1 Like

Hi Rafael,

The public access modifier makes a variable accessible for everything that has a reference to this object. In larger projects, this could make debugging very difficult because if “everything” can access “everything”, you have to check everything. For this reason, it is good practice to make things private whenever possible because that makes debugging way easier. In this case, our variable is private.

Did this clear it up for you? :slight_smile:


See also:

5 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms