What is [NonSerialized]?

💎Useful Unity Attribute

[NonSerialized] attribute is used to make a public field not serialized in the inspector.

When applied to a private field, it stops serializing the field during a hot reload.

Hot reload is when you update a script while the Editor is opened and Unity applies the script changes immediately.

If you want a reference to be null after reloading from scripts. In this case, use the [field: NonSerialized] attribute.

𝗧𝗵𝗮𝗻𝗸 𝘆𝗼𝘂 𝗳𝗼𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴! 📖

♻ SHARE and serialize my content to be seen on your connections feed

If you enjoyed this explanation, consider joining 300+ other engineers in my newsletter to improve your game development and design skills.

Subscribe here → https://dev-insights.tech/

What is [NonSerialized]?

--

--

Djordje Vuckovic

Hey there! I'm Đorđe, and I'm helping you and myself become better Unity game developers. Let's connect on LinkedIn: @DjordjeVučković