-
Notifications
You must be signed in to change notification settings - Fork 5
PersistentData
Persistent data is a set of entities that live on the Global Systems stack and persist throughout life cycle. It is essentially just a root object for any entities you add to it. You can save and load persistent data separately from scene data and configs. Having separate persistent data files will act as "profiles" where you can store player progress. You can mark entity as persistent, and it will be moved to persistent data root:
entity.MakePersistent();
This essentially just moves the entity to DontDestroyOnLoad scene and parents to PersistentDataSystem. Use this to implement item transfer from the world to player inventory, and similar uses.
CompRef will only serialize references to components inside persistent root. Upon load all the current children of persistent root will be destroyed, then after one frame the data will be loaded. When completed, event
PersistentDataSystem.OnPersistentDataLoaded
will be called.
Best practices would be to create specialized data holding entities. Example:
Here you can see a special entity holding player status data, it will be fully serialized. Since entity task is to hold user data, all it has is put into SerializedData, because we don't need anything prefab specific.
Player inventory has a Blueprint loader that on startup will unbox the initial player loadout, and self destruct.