Skip to main content

Serializable

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it across the network. It is called 'serialization' because it involves turning what is sometimes a complex tree of data into a linear sequence of bytes.

Some functions are only compatible with types that are serializable. For example, a preference can only store serializable values as they must be stored and loaded across multiple episodes of the game.

Only the following types are serializable:

  • null
  • Boolean
  • Number
  • Vector
  • String
  • Color
  • Flags
  • Symbol
  • Keycode
  • Array - must only contain serializable values
  • Map - must only contain serializable values

Note that the following variables are not serializable:

  • undefined is not a serializable. It will just be serialized as null if it is encountered.
  • Entities is not serializable.

It is best to only serialize public Symbols (e.g. pub symbol WantsFireball). Private symbols must be serialized with their file path to ensure they remain unique, which means serializing private symbols is not robust to renaming or moving your source files.