add an interface to your actors you want to save
the interface can return custom savegame data if you want (worry about this late)
OnSave, GetAllActorsWithInterface->GetSaveData->AddtoSaveArray
OnLoad, GetAllActorsWithInterface->SendInterfaceMessageToDestroy
we use a message so we can override if we choose to.
the SpawnAllActors from AddtoSaveArray.
i’ll actually release a plugin that does all this soon but the above logic is pretty simple
I’m sorry, I’m confused how to spawn the actors, and where to spawn them? This is what I have (I can’t find the information to plug the spawnActor without error)
so you have an interface, in that interface make a function called GetSaveData which returns whatever you want to save,
this will be a struct with at least ClassToSpawn and Transform.
Your save array will be of this struct
when you spawn you have the Class/Transfrom ready from your SaveStruct
Alright so I’ve tried to do so, I think I am understanding how to do this, but I’m getting an error, and when I load into the game, no objects spawn. Here’s how the blueprints are looking;
Save Inventory:
Load Inventory:
GetSaveData:
Here’s the error:
Blueprint Runtime Error: “Accessed None trying to read property As Save Data Level”. Node: Branch Graph: ForEachLoop Function: Load Inventory Blueprint: C_InventorySystemComponent
Blueprint Runtime Error: “Accessed None”. Node: Branch Graph: ForEachLoop Function: Load Inventory Blueprint: C_InventorySystemComponent
Okay, that error is resolved. Now I’m having this error;
Blueprint Runtime Error: “Accessed None trying to read property As Save Data Level”. Node: Set Content Graph: LoadInventory Function: Load Inventory Blueprint: C_InventorySystemComponent
Blueprint Runtime Error: “Accessed None”. Node: Set Content Graph: LoadInventory Function: Load Inventory Blueprint: C_InventorySystemComponent
Blueprint Runtime Error: “Accessed None trying to read property As Save Data Level”. Node: Add Unique Graph: EventGraph Function: Execute Ubergraph BP Base Parent Item Blueprint: BP_BaseParentItem
Blueprint Runtime Error: “Accessed None”. Node: Add Unique Graph: EventGraph Function: Execute Ubergraph BP Base Parent Item Blueprint: BP_BaseParentItem
Blueprint Runtime Error: “Accessed None trying to read property As Save Data Level”. Node: Add Unique Graph: EventGraph Function: Execute Ubergraph BP Base Parent Item Blueprint: BP_BaseParentItem (this part repeated excessively)
which has something to do with the content being invalid, likely because it’s not in the level?
I’m sorry for my lack of knowledge on this subject- I don’t think I’ve successfully figured out how to make sure the world is ready, I’ve tried but there isn’t much information I can find on how to use the ‘is level loaded’ node, assuming that’s what you’re speaking of. Also, would it be benificial to create a loading screen while loading the level, assuming once the game is put together it’ll take a second to get everything together.
ah your gameinstance has 2 savegame objects writing to the same Slot, i’d assume the second overrides the first.
you can have 1 savegame object with multiple variables inside. otherwise level data i’d usually save to something like SLOT_LEVELNAME
you GameMode beginplay means the level has loaded however it will fire before some actors so the delay is just to ensure actors have initialized.
probably a better idea to keep the savegave stuff inside the GameInstance not the GameMode. the GameInstance could even load level data before you load the map
Yeah, I was wondering about that. I have multiple savegame objects to organize between data saved, because there’s all types of data to be saved. Should I only have one? If I recall correctly, the tutorial I was watching created two, one for inventory data and one for level changes.
I’m slightly confused what you’d like me to move from the gamemode to the gameinstance, honestly I followed ryan’s save game tutorial, and while working with you on this, I’ve been building upon it with another tutorial that is supposed to be an ultimate save system, but I’m struggling to keep track of them now.
How would I save the data from the two savegame objects to one slot, or do I have to move them into the same object?
Also, is my code in my game mode and game instance doing the same thing? It looks to be. I think there’s some confusion for me about the two different tutorials and what they had me do. I started this one {https://www.youtube.com/watch?feature=shared&t=1238&v=7gfA-QO5pA8} which is where I believe some of the code is coming from.
The tutorial above had me call it something similar to SLOT_LEVELNAME which you can see in the game mode.
you can have multiple saves but i think they’d need to be in a different slot.
or use the same save with different variables, ie mapdata array/player data array
yeah the issue is just you have both for some reason. Get rid of one, doesnt matter which. Personally i prefer GameInstance so some data can carry across levels such as PlayerData but either is fine