The title may sound weird but what I mean is when an actor is destroyed and then the game loads to be able to keep all those actors from spawning. I’ve been looking at many tutorials or other similar questions that have to do with save games but nothing that involved destroyed actors.
you can give every permanently destructible actor or pickup item a unique ID, and when the actor is picked up or destroyed, you can add that ID to an array in the playerController or playerState, which gets saved into a SaveGame.
then, inside your destructible/pickup actor, on beginPlay, you can get a reference to the player controller/state, and search the array of destroyed/collected actors. if the ID of the pickup item is in the list of collected items, destroy the pickup item. if its ID is not found in the array, make the pickup item visible and enable its collision.
That is pretty much the last thing I tried to do but didn’t work. I’m confused with the part you mention in your second paragraph, if all my pickups are of the same class (blueprint) then how can I give a unique id to each and then know which id to get from the list.
the ID is just an integer or name variable inside the pickup blueprint. when you place them in the level, or spawn them in during gameplay, you set the ID to some unique number or name. then on begin play, the pickup searches through a list to see if its ID is in the list.
for the ItemID, use a name or integer, instead of a boolean.
all local variables die when the pickup is destroyed and reset every time the pickup spawned. so passing Self actor references into other actors, or toggling local booleans right before destruction is useless, because that pickup actor is getting destroyed, and that reference will become invalid.
you should pass the ItemID to your save game function, instead of that (soon-to-be-invalid) Pickup actor reference.
then in the variable’s details panel, you can check Editable and ExposeOnSpawn. that way, every time you spawn the actor, you can set its ItemID.
in the begin play event you should use a Find node, instead of the ForEachLoop and you should use a Name array or Integer array for the collection of ItemID’s, instead of the boolean array.
Alright I’m getting close but I still got small issues. 1st image is what’s inside a box blueprint I made to test this. 2nd image is the save game function and 3rd image is the load. It works but only destroys the last box i’ve destroyed before quitting the game (i destroy them with linetracing nothing to do with this) while all the others just give me the string “not destroyed” from 1st image.
I understand what you’re saying but if that was the case then shouldn’t it not work at all instead of working for the last pickup destroyed only?
Anyway I tried it with an Integer instead of a boolean and the exact same thing happened. If I put 3 boxes and destroy them in random order, only the one that I destroyed last will not spawn…
Also I noticed after a little debugging that in my 2nd image where i add the boolean (or the integer trying to use your method) a print string always returns me index:0 so probably that’s the issue about why I only get the last one but “add” is supposed to increase the array size every time something gets added so no idea why this happens.
I feel like this is something that someone could probably do in 30seconds if he actually knows what he’s doing…
Edit new images: Append gives me the correct box id so the correct value is sent
Index# always returns 0 so every time a box gets destroyed its ID is stored always on index 0 which is what causes only the last destroyed to spawn (I have no clue why it doesnt increase)
Well after looking at this image I can put the first part somewhere else to run it once but doesnt really matter, the issue is on image 2 with the array index.
dont pass an actor reference into your save game function. that Self actor you are passing in, is invalid, because you destroy it. actor references can only be used if they are valid, meaning they are referencing an actor that is still in the world, and has not been destroyed. instead of passing in the actor, just pass in the integer ItemID to the player’s SaveGame function.
But that’s what I did, I passed the BoxID which is an integer.I edited some comments to the last images , not sure if you saw them but I explained everything that’s going on I think.
after load game or create save game, you should cast to your custom save game type, before setting that SaveGameSubClass reference.
also, instead of using create save game, you should be using load save game, so the new additions are added to the already existing save game, instead of replacing the old save game. otherwise, only the last item would exist in your inventory.
Did those last fixes you mentioned and it works! Thank you very much.
I did every step you do , but the actor was destroyed still return and not saving
are you solve this issue??