Array item in SaveFile turns NULL in few seconds

Hello devs :wave: Sorry for bothering you but I really do not know what is happening right here :sweat_smile:

Can someone explain to me how it is possible that a variable which is in SaveGame FIle becomes NULL after a certain time? (Time is changing each time I start the game)

Nowhere in the code I have told that I need to remove this variable or set it’s name to NULL. I am just adding the actors to this array, nothing more, nothing less. I am using only ADD to add object to the Actor Array.

The NULL is acting like an actual actor in the array. When I add different actor to that array there is [NULL, ObjectName] Other arrays are working fine in the SaveFile

There is nothing in the video really for the whole 50 seconds or so, you can skip to the end. An idea is I am doing literaly nothing to change the variable and it still goes to NULL

Big thanks to anyone who read this:pray:

It will because your code is overwriting the save game… Either that, or clearing the item in memory.

Can you show your savegame code?

I figured out, that when I destroy the actor in few seconds, the variable will itself sets to nothing.

Please ignore that it looks awful :smiley:

I’m wondering how the game mode makes sure the save game is there. Does it by any chance always create it?

Yes, I have a few saves which are created right at the begining of the game. And this one is one of them

Yes, but if you make a new save game when you save, a new save game is empty. That’s it.

I am creating the save only if the save has not yet been created.

Ok, just checking…

So I know why it is happening, but did not expect that.

When you delete object from the level, and that object has a reference in the SaveGameFile, the reference on that object will be renamed to “None” in random time, could it be 10 seconds, it can be 1 minute. When you destroy it and quit the game, it will stay saved. So my brain is telling me that this is somekind of a bug I found out. But probably I am missing something :thinking:

I did not think that this could be a problem, when you Save the variable, you saved it. I understand that Objects are already created instances of class. But … why?

You can’t save actor references in the save game. Every time you run the game the actor refs are different.

Actor ref is a ‘this run time only’ time arrangement.

If you want to be able to remember which actor was doing what, you need to have them in an array and know which is which, by index.

You can save actors. I was able to save the array of actors. I am still able to save it.

I can do something like: “Take this actor → save actor+transform-> exit game → Actor will be spawned on level creation → Load the actor+transform” The same actor will be at the same place before I exit the game.

The problem comes with this. When the player would be a little bit longer in the game, and you make a save file with actors, in few seconds that Save Actor will be gone.

Oh, and you wrote “you need to have them in an array” so you meant as class reference?

You CAN save actor references, yes, but in the long run, it won’t work. There’s no guarantee ( at all, especially with packaging ), the references will match.

You can give every actor a tag or id, and you have two arrays. One of the IDs, and the other of the transforms. That way, you know which actor goes with which transform.

Ye, I did not know that object references are so unstable.

Thank you for the pleasant conversation and for information and of course for your time. Good luck with your Project :slightly_smiling_face:

1 Like