Instance Objects

Each instance (dynamics and statics) have an object that is related to.
These objects are for your own use and can be any UObject.
These objects does not have an identifier and are get/set/load/save using an instanceID.
You can manage these objects yourself but cannot use normal serialization nodes.
Right click in blueprint and search “instance object”.

This is an option in the advance part of “Instance Settings”.
The goal of this feature is to make your instances persistant trough game sessions.
The loading part is automatic and will be done before any BeginPlay event.
The save part is done :
– Yourself using a saveInstanceData node.
– Using a DTA gameInstance (Project Settings/Maps & modes/GameInstance Class). This doesn’t work on mobiles, save is done after EndPlay.

Are two different features that you’ll often use together.
This tutorial use both, look at WBP_PlayerList_B6, and compare it with WBP_PlayerList_B5 from the last tutorial, you’ll understand that our life is easyer with these options.

In previous tutorial, we had a WBP_PlayerButton that stored thing related to our savegame.
Now we are using it too but we don’t manage these, we just create these when we create a new instance for a new player.

Once an object is set to an instance, we don’t need to generate it again, with “AutoLoadInstances”, objects are generated by the master.
At beginPlay, we already have all instances and instanceObjects using GetAllInstances. We still need to add them to our VList because UE build-in widget‘s serialization don’t store things like that (set them deepObject is useless).

This blueprint is not an Element because it’s not needed, we never save anything about savegames, we only manage saving/loading games.
In B5, we saved the current instance as “currentPlayer”, our map, and deepSaved the values in this map.
Now we use “AutoLoadInstances” and a GameInstance_DTA, the list of instances, instanceObjects and current instance are saved and resored automatically.
On mobiles platforms, there is no endgame events neither any really working app end detection. A workaround is to listen the event ApplicationWillEnterBackground of a application Lifcycle component.

GetInstanceButton macro:
We made this little macro because our instance objects will always be WBP_PlayerButton_B6, we just made the getInstanceObject better match our project

Event beginPlay
At this time, instances, instanceObjects and current instance are already restored.
We do a foreach loop on AllInstance for :
– Delete instance that was deleted in editor (or explorer).
– Add our buttons to the Vertical Box.
Then we deserialize the current instance.