i’m trying to update a variable using load/save game from slot. Everytime a enemy dies I run a branch, using a bool variable ‘isDead’ (false), I ask if ‘isDead’ is false, if is false, set to true then run code. This way I make sure the code is executed only once. Inside the code is the image
However this does not work properly the variable “kills” is not updated. ok, I put the load/save before the branch and works, but it adds 1 several times.
Could put a print statement after the function call to see exactly how many times this function gets called. Maybe you can figure out why this is happening???
It is weird that “kills” does not get updated. Maybe add a print statement after “set IsDead” to true to make sure that this indeed is running. Maybe something else is setting “IsDead” to true and is causing this code to not run???
I wouldn’t do saves like that. In a Multiplayer game, I’d have the kills updated on the server side GameState, liked to the index of the player controller. Then when I wanted to save, I’d set the value into the save actor and save it. With this, if you kill like 5 things at once, then 5 loads and changes and saves happen all at once. It’s difficult to control the save and loads for debugging.
You shouldn’t need to load each time either. See basically Load = “Spawn SaveGame Actor.” And it creates an actor with values taken from the save directory on the hard drive. Then you can get a reference to the version in memory. You don’t need to pull the info from the save directory each time. You don’t need to cast to it each time. You can save it each time if you want though.
Having said that, maybe you only get a kill every minute or so with a boss and this should be fine. I’d do this: I’d have a print string at the start so it ALWAYS runs. I’d append the string so I could get numerous details on one line. I’s want to know “IsDead” and anything else. At least have "IsDead = " and the value after. I’d also have a reference to the save so I can pull data from it any time I want. I’d get the kills variable from the save reference and print that too. ". Kills = "
I’d have a Print string for the CastFailed, so I see if the cast is failing.
I’d also have a print just before the save to check the value of kills there after it’s added 1.
There are some things you can try. Async Save has a success option so you can see if the save succeeds. You can also use the “Increment” node. “++”
But that should really let you know what’s going on.