Game Instance is not saving array

I am trying to make my game remember the level state between deaths.

Right now, it works as follows:

  • Collected items and destroyed objects are stored in the game state temporarily.
  • When the player reaches a checkpoint, items and objects are pushed to the game instance so that they can be removed from the level if the player dies and counted on level completion
  • At the end of the level, objects and items on the game instance are saved to a save file.

Retrieving variables on respawn isn’t normally an issue, for some reason the array of objects is empty when I try to retrieve it from the game instance after respawning.

Maybe a silly question, but as I understand: Your have an array of objects right? And correct me if im wrong but wouldnt these objects and actors you are referencing to, removed after reloading your level?

But someone maybe correct me :sweat_smile:

I usually use Structs to save objects to a file

Hey @sweeetjd! Been a minute.

So you said you were pushing the object array to the Game Instance.

Could you show the code for how you’re doing that? It’s possible you’re overwriting the array?

Also make sure you’re not loading up a different game instance file (it’s possible).

But yeah the code for how you’re doing this! Just so we can see how you’re going about this to be able to understand what could be going wrong. :slight_smile:

1 Like

That makes a lot of sense. I was trying to avoid saving to a file just because I’ve had so much confusion with it in the past but now that you say that, I’m not sure how it could be done any other way. Thanks!

1 Like

Hey @mind-brain yeah it has, finally have time to make games again!

I think callfreak is right. If the level is resetting then the objects no longer exist to be referenced. I’m going to try using a saved game instead.

1 Like