Skip to main content

Favorites

Painter’s Favorites list is a visual representation of data stored in a Scriptable Singleton instance. When the instance is saved, the data is serialized to the file system.

The serialization is performed like any other Unity serialization: references to scene Objects are lost. This creates a problem because TilePlus tiles found in Multiple-selection picks from a Scene in the hierarchy are scene objects: saved with the scene but they do not have corresponding Project assets.

Instead, these tiles are serialized to JSON using EditorJsonUtility.ToJson, and the output string from that method is what’s stored. When the Scriptable Singleton’s instance is loaded, this string is used to create and populate a new TilePlus tile which can now be painted.

This approach removes the need to create many new asset files for the TilePlus tiles, which makes little sense for a transient storage container such as Favorites.

The downside is that every time that a new Favorite item is added to the list, the entire list is serialized and saved. Each Multiple-selection Pick in Favorites has two potentially large items:

  • The generated Icon for the Pick.
  • The JSON for a TPT tile.

The Icon is saved as a PNG and is compressed. The JSON data are strings in a condensed format.

Keeping response times short is the main reason that Favorites is limited to 32 entries.

If the process fails in any way and null tiles end up in reconstituted Multiple-selection Picks, then the entire Pick is discarded.

The list of Favorites will be automatically truncated if the number of Favorites exceeds 32 entries when the Favorites data is saved to the file system.