Hi guys
I’m making a game involving multiple scenes and resources. While some resources can only be gained and spent by building buildings in specific scenes, I need the resource counter to keep increasing no matter what scene you’re in.
I asked for help on the forums and gotten some great feedback, but a new challenge has emerged.
Currently my situation is that I have the object containing the resources (and their amount) as a singleton, loaded in the start scene.
To calculate the resource income I do however need to make use of an array refering to the objects with my buildingMananger-script attached, and for some resources these are placed in other scenes, meaning that I can’t reference them from the getgo, which result in them not being implemented to the singleton resourceManager at all.
I thought about making the buildingManager-script static, which should allow me to reference them in the singleton array in located in scene 1, but I cant figure out how to make arrays work in static classes.
I guess another option would be to make all the buildings singletons placed in the first scene, but that appears to be even more cpu/memory heavy to me.
Either way I’m not convinced that any of the two options are the best approach. I keep reading warnings about too many statics/singletons, and this would result in a lot of extra statics or singletons depending on the solution.
Now I’m halfway to a solution that requires neither, were a resourcePerSec singleton recieves the building data, once entering the relevant scene, but that would create the another problem when loading the game, if I understand the function correctly.
In this case if the player had saved the game and closed the game, while having enough buildings to give a +10/sec bonus of a specific resource in scene 3, wouldnt that bonus first activate once re-entering the scene once more after loading?
I hope the overall problem is clear, but if not I will elaborate further ![]()
What would you consider the best solution for a scenario like this?
Thank you for reading
ps. In case anyone are becomming annoyed by my stream of questions regarding singletons, dontdestroyonload, statics and other related topics, please bear with me. This is a pretty abstract concept to me, but so far the community has been such a great help so far in helping me understand it ![]()