What does "[SerializeField]" do and why is it in those square brackets?

Hi Svetlin,

[Serializefield] is what is known as an attribute, it can be used to decorate a field (member variable). Attributes are placed within square brackets.

The use of this attribute is to expose the member variable within the Inspector without having to give the member variable a public access modifier, e.g. it can remain as a private member variable, not accessible to other classes.

Please note, it’s better to copy/paste your code into your posts on the forum and then apply the code fencing characters, before and after, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages but for code they tend to be less readable, especially on mobile devices, which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type out a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Hope this helps :slight_smile:


See also;

2 Likes

Privacy & Terms