- Home /
GameManager and scene design issue.
I am an extreme noob on both unity and programming in general so sorry about that.
In this first unity game thingy ive been working on, (2d endless runner) ive created an game object called GameManager with its script.(it is singleton and it doesn't get destroyed after scene reload cause it made sense to me idk). Since i wasn't planing to make this a huge game i thought this could handle generic stuff like displaying ui, stopping scene, reloading scene etc.
So I made a canvas for death screen which gets activated by this GameManager. But the issue is, in the next/reloaded Scene, GameManager tries to active the old canvas. (The deleted one from the old scene)
Should i turn canvas into a nondestroyable during scenes? What is a good design for a simple endless runner game? Is making GameManager nondestoryable during scene reloads is a bad idea? How would you design something like this? Any resource links about stuff like this?
I feel like i am doing something wrong by reloading the whole scene. Maybe i should make a separate level designer object and reset the level through that? As i said i just don't know. Simply learning the unity's editor/syntax is already too much for me lol :'S
Answer by TanselAltinel · May 11, 2018 at 11:12 AM
Hi latbat58,
We all started from some point, nobody was born with Unity knowledge :)
I personally think, for game managers and such, singleton might be a good choice. And I also think, if a game object is going to be used over all scenes, there is no need to destroy and re-instantiate it, since it will waste resources in vain, while you could use the already existing one.
However, you can also modify your script to get the new canvas in each scene load (SceneManager.sceneLoaded), so you will always have the current instance in your game manager.
However, good practice in Unity, is to re-use objects instead of destroying/instantiating them. So I think you are on the correct path.
Also, if it is a generic endless runner game, you can check some tutorials on YouTube, or even official tutorial: https://unity3d.com/learn/tutorials/topics/scripting/lets-make-game-infinite-runner