Posted January 07, 2023 by Justin DaSilva
#first game #learning #unreal engine #lucifers hordes
This was our final week to add anything new to the game. One thing we tried before but couldn't really figure out at the time was saving the player data throughout a run. The data would be the player's stats/attributes, the weapon they had equipped and any abilities they picked up. The problem that the team had before was saving the weapon which was an Actor meaning it had to be spawned in the level. They would try to save a pointer to that object, but because the Actor was spawned they were saving a reference to the instance of the object in that level which would be destroyed when the player moves to another level, so nothing would be saved.
After giving it some thought I decided to give it a try and I was able to come up with a couple of solutions. I knew we didn't need the specific instance of the players weapon from the previous level because the weapon's properties would never be permanently changed throughout the play session. We just need to save a reference to the default object and the way I know how to do that is with TSubclassOf. I was able to store the players weapon at EndPlay of the previous level and then spawn and set the default object of the same weapon at BeginPlay when the new level loaded. Unfortunately, this only worked in the editor and didn't seem to work in the packaged build. It seems to cause the game to crash. This is something we will have to figure out for the final week.