I've seen Serializable more lately. How/Why do programmers use it?

It seems a lot of Unity Programmers use [Serializable], wanted to know what people use it for and whether or not it makes cleaner code.

To elaborate on Raresh’s answer, you’ll usually see the Serializable attribute used on custom classes.

Normally when you create a class it will inherit from MonoBehaviour and Unity will automatically know how to serialize the class, meaning you can view and edit it in the inspector and your changes will be stored.

In cases where your class doesn’t inherit anything (or in other words inherits System.Object), Unity won’t know how to serialize it and it won’t appear in the inspector unless you use the Serializable attribute.

You can then create public fields of your class type, e.g.:

public class Player
    public string name;

public class SerializationTest : Monobehaviour
    public Player player;  // This field will show up in the inspector

See what happens if you remove the [Serializable] attribute :slight_smile: