Persistent Values
An easy way to persist values inside of an actor, using the KVStore
Last updated
An easy way to persist values inside of an actor, using the KVStore
Last updated
BPMC_PersistentValuesBase is a Morpheus blueprint component and is the base class for saving, querying and loading values. There are two other components which inherit from that class for persisting String and Int values, BPMC_PersistentValuesString and BPMC_PersistentValuesInt. The purpose of these components is to easily wrap the process of persisting values in one place. You can add as many components as you like to an actor.
It’s very simple to setup these components, you just add them as a component to an actor and setup the configurable values in the Class Defaults. Under Config > Setup, there is an EventKey (Name type) which determines the unique key type associated with these persisted values. Each component should be setup with the intention of persisting values specific for an event or feature. String values are stored in a String Array and Int values are stored in a Name<>Int Map
, where each name should be unique to the Int value being persisted.
There needs to be a valid EventKey
for these components to work. You can either manually setup the value in the Class Defaults or dynamically by calling DynamicallyOverrideEventKey()
You can also dynamically override the values that are being persisted by calling the relevant function for each type of component, DynamicallyOverrideStringValues() or DynamicallyOverrideIntValues().
To save the values there are a few different functions that can be called.
SaveAll()
SaveSingleValue(String)
SaveSingleValue(Int)
These will save the passed in value to the player’s web profile in the KVStore if UpdateValueInDataStore is TRUE (which is default). This will mean it is saved persistently across sessions and events.
To load the values there are a few different functions that can be called.
QueryAndLoadAll()
QueryAndLoadSingleValue(String)
QueryAndLoadSingleValue(Name) → This is for the Int component
Once these functions are called and completed the components will store them. For Strings it’s GetPersistedStringValues() and for Ints it’s GetPersistedIntValues().
There are two general delegates that can be bound to by any component inheriting from the base class:
BindToSavedDelegate()
BindToLoadedDelegate()
There are also specific ones for Strings and Ints to know when the values are saved/queried/loaded.
BindToAllStringDelegates()
BindToStringSavedDelegate()
BindToStringLoadedDelegate()
BindToStringQueriedDelegate()
BindToAllInDelegates()
BindToIntSavedDelegate()
BindToIntLoadedDelegate()
BindToInQueriedDelegate()
The handle functions always returns a Key and PersistentComponent to know which one it’s related to. For specific ones it will return a String or an Int value. You can use the general ones and always cast the component to the type you are using if you have a few persisted components attached to an actor.
There’s currently no support for Struct values as you can’t store wildcard variables in blueprints. However, if you require one for a specific Struct a new child class can easily be made inheriting from the base class and set up in it’s own component.