What i am trying to do is saving the opened boolean, ok so basically when you open the chest you can loot it, and let’s say you pick something up from the chest, you wouldn’t want it showing up again when you open it for a second time. So i want it to save the inventory of the chest i have tried this but it doesn’t work
Hi POOOOOfsfsdfsf
You kind of have the right idea. It appears you are working backwards. Once the chest is opened, you are then creating the save object and then apply the default value.
-
Initialise the save object on BeginPlay in a relevant class such as GameInstance, PlayerController or GameMode
-
Add a function / event in the chosen class to apply data to the save object and save it.
-
The best way to go about something like this, is by giving your chests and “ID” or GUID. This is so you can identify the chest when reading the data from the save object.
-
Add the logic in the chest object to store the opened state and then call the event / function in your chosen manager class to write the data to the save object.
-
Add logic to the BeginPlay on the chest object to read save data from the manager class (if it exists) and apply it to the object. **NOTE! Becareful with begin play as the it might be called on the Chest object BEFORE the manager object (unless GameInstance). **
I have created a quick example using a PlayerController below.
I hope this helps. Good luck!
Alex