The backgrounds are driven by the FlowGraph. So the VNEngine saves the state of the FlowGraph, which is what will restore the background when save state is restored. That is the
vnengine-graph graph entry in the json file.
VNNode_ChangeBackground.cs There you can see how it has a function called
RestoreFromPersisted() that is run when that node needs to do something related to loading from saved data. What exactly happens in there will depend on the node and some nodes, like
VNNode_CharacterAction does not support this at all since it does not make sense for them to do so (in this case the node is just an interface with the VNEngine which will take care to save and restore characters.
The “saving” part is quite simple. When the node executes it updates a key, background for example does this
SetPersistData("bgsvn-back");. This will create an override on that key so that now this specific background node is the one to be restored and no other background nodes in the same graph (or linked graphs) since it override the key called
bgsvn-back. All that is saved is what node is related to that specific key and then the FlowGraph is restored from save data it will run through all the saved keys and execute the associated nodes. Note, the full function is
SetPersistData(string key, int loadOrder = 10, object data = null) so it can accept data if the node need to save additional info.
There is also
RemovePersistData in case you had for example a clear background node (not areal thing… just example) and needed to get rid of the save entry made by a previous VNNode_ChangeBackground node.