Tower Defense Scene Management Issues

April 25, 2019

Scene Management Solutions

Identifying Issues and Possible Solutions

Scene Conflict
  • There are two scenes that load at the same time that have scripts within them that want to reference scripts within the other or both reference the Logic scene which needs to be updated simultaneously
  • Even though they should ideally be loading at the same time, one is always loading ‘just before the other’
  • This causes the first scene loading to miss its references since the other scene does not exist to it yet when it goes to get those references
  • The second scene loading in does however load its references properly
  • I’ve tested switching the order of loading and the second scene functions properly consistently, while the first scene has errors
Current Issues
  • Level scene loading second to make sure the nodes can get the BuildManager reference
  • However, the Level scene sets the number of lives the player has (LevelPlayerStats passes lives in to the PlayerStats script in the Logic scene)
  • The LevelManager in the Base scene checks the player lives to see if it should end the game
  • Since the Base scene is loading first, it checks and sees there are 0 lives before LevelPlayerStats can set the correct amount of lives for the level
  • This is setting the game to Game Over immediately
Proposed Solutions

Find way to time events: Setup the scene manager system in a way that it makes sure everything is loaded before attempting to setup references. Functionality of the game also needs to wait some time to make sure the newly loaded scenes have time to set the values necessary in the Logic scene before actually starting so they don’t try to work with default values instead.

Move references: Currently the issue is that no matter which scene loads first, there are reference timing issues with one of them. This could be evaded by placing all of the references that should be done first into the same scene and just making sure that scene loads first.

I believe the timing control solution is the better and more powerful solution, as this will help anytime I really need to have multiple interscene references in the future. That is also the much more difficult solution though. I may go with the simpler solution for now just so I can continue experimenting with the more game design heavy concepts of working on the tower defense game and then come back to figure out the stronger solution later.