Issues with Saving Plant Growth


Author: Zoleda Davila

Posted on 2/16/24

This week, one of my tasks was to give the game the ability to save plants and their information when you leave the farm map. We wanted this to happen so that when you travel back to the farm, the plants and their growth progression would be there and the player would not have to replant their crops. This was causing much difficulty, because each plant should have their own growth progression. So, I needed to find a way to make each plant have a unique variable, so we were able to spawn each acto with their own specifc features. At first, I believed that we could give the plants their own index. The problem was where we could set the plant's index, so that way they were all different.  I had set the plant index in the begin play; however, when testing it out, each plant would still have the same values for their harvest, health, and water components. 


Later on, while debugging, I found that three components were getting set way before it was hitting the setting of the index. They were also all getting the same values, because the default value for the index was 0. So, as a result, all the plants being spawned in were getting the same info as the first plant in the plants array in the game instance. As a solution, I found that you can expose a variable when you spawn an actor, This would allow the index to be set before any of the components and other variables would be set. I would also set the default index value to -1, so it would not effect anything that has to do with the array.

Then, when we need to spawn the actors again when we travel to the farm, we can have the plants array control the index in the plants blueprint it self and each plant can have their own information and growth rate. in the game instance, we go through the array for plants with a for each loop. Then we cast the class to the parent Plants class, so when we call Spawn Actor all the variables that need to be set upon spawn will be shown. When testing this solution, we found this way to be the best right now for this stage in the video game. 

I believe with this method of saving the plants when we come in and out of the farm map in our video game, we will be able to save much more elements in our video game.

Leave a comment

Log in with itch.io to leave a comment.