VN plugin. Background saving


(Maylin Liaran) #1

Hello. I’m trying to implement backgrounds not as a single sprite, but as a prefab (and manage them from prefab base, similar to your characters database implementation).

But. I cannot understand how you persist an active background so a user will successfuly load from a file. JSON save-file keeps info about active characters, global variables and the last node, but nothing about background.

Also I noticed that when it’s time to load characters VNCharacterManager.RestoreFromSaveData(List data) creates new VNCharacterAction’s, fills them with persisted data, performs them and thus brings chars back to scene.

But how background save/load is handled? Is it somehow searches for the most recent VNNode_ChangeBackground in FlowGraph and performs it when the user loads?


(Leslie Young) #2

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.

Check out 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.


(Maylin Liaran) #3

Thanks alot!