Saving Player Items, weapons, and money between levels
Author: Najee Jackson
Problem
The player gains a couple of weapons and powerups at the beginning of the tutorial level, as well as cash to use at the upgrade bench and shop, but once the player goes to the next level, all of their upgrades, money, and weapons disappear. This made it impossible for the player to progress through the game, as they couldn't kill any enemies to get to the next room and progress through the level. This hindered the player's sense of progression as they got stuck in a level without any means to escape.
Solution
To fix this, I added three functions to the Game Instance to save the player(s) weapons, powerups, and money. The first one to save the player's weapon was the most tedious. I first had to get the players who held weapons, which I did have access to due to a variable in the Game Instance; once I found those, I had to figure out which weapon the player had equipped before they entered the next level. To do this, I checked their weapon component and saw what weapon was in the currently equipped variable. Once I got this information, I waited for the game to create the next level. Once it was created, I looked through the players' weapons array and created actors from the class name. Once I had both weapon actors spawned in, I called the interact function on both weapons so they would be in the player's inventory on spawn. I then had to set a couple of variables in the weapon component so it knew which weapon was being used before the level load. I did something similar to save powerups and money between levels, but instead of using a list, I used a map to save each player's list of powerups and money separately. Before the player entered the next level, I used the players' index as a key in a map and stored the list of items they had at that key. I did the same thing to save money between levels, but instead of using an array of items, I used another integer for the player's number of coins. Once I had that and the next level loaded, I went into each map using the player's index to get the values at that key. For the powerups, I respawned them on the player so they would auto-pick them up at the start, and for the amount of money, I set the player's coins to be the same as the value in the map. These functions helped store the players' progress between levels, making the game feel playable and rewarding.





Comments
Post a Comment