I am working on a saving system in UEFN that would save player’s inventory.
The idea is: there is a SAFE zone in which you can leave the session and keep your belongings, but there is also a DANGER zone in which when you leave the game, you lose everything.
So I have a periodic save loop while in the SAFE zone - that works perfectly fine. I check for player’s state kept in a player → state map, and if its SAFE then I save game. That means when player dies (dying is only possible in the DANGER zone), drops all his stuff, and respawns in the SAFE zone with empty inventory, save happens and he has nothing - that works fine.
But there is an issue - player can leave the session by going back to lobby while outside of the SAFE zone. Leaving the game means being eliminated, so his belongings drop on the ground, but when he rejoins the game, he has everything in his inventory - that makes sense because last save happened a while ago, when he was still in the SAVE zone.
To handle such case I subscribed to an OnEliminated event from fort_character, I check if he was in the SAFE zone or not, and if not, then I save the game. Sounds like a solution but it is not - for some reason catching this particular moment is not possible. I wonder if maybe Player reference is no longer valid in such case, so attempt to save the game no longer works. Subscribing to OnRemoved event called by playspace also doesn’t work.
Does anybody have any idea how to solve the issue?
You need to clear the player data through DEB using a trigger to wipe the already saved data when your player leaves the SAFE zone
1 Like
This is it! You are my savior, thank you Such a simple, elegant solution that didn’t come to my mind.
One important thing to add - apart from the player’s inventory, there are persistent player stats saved with a weak_map which are permanent and not affected by death, like reputation with certain factions, player level, etc. Those are obviously not cleared when triggering ClearData on SavePointDevice, which in my case only affects inventory and resources and that was exactly my intention.
1 Like
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.