Project Boost Dialogue System Singleton

Hi Everyone,

I’m expanding Project Boost to include a full game loop. However, I’ve encountered an issue.

The game now includes a dialogue system (canvas) that displays at the beginning of each level. When the player dies, the level reloads but so does the dialogue system. For context, the dialogue system uses a simple canvas with a typing effect.

The functionality I am aiming for is to have the dialogue display once on the initial scene load. If the player crashes and the level reloads, it will not display again.

Is the correct solution to use a singleton? Or, is there a more appropriate way to disable the dialogue when the scene reloads?

I’m happy to share more details if needed. Thank you in advance if you are able to assist me in resolving this issue.

Wouldn’t you be able to just have a bool variable checking to see if the player has already done this level already? Kind of like lives.
bool isFirstTime = true
Once the dialog closes, isFirstTime changes to false until the player makes it to the end, in which isFirstTime is set back to true for the next level load?

There are two possible solutions to this, depending on what you want to happen when the player replays a level in a different session or not.
If you’re only worried about not repeating during this play session, then as much as I hate them, a Singleton may be just the thing for you…
If you only want the dialogue to play once for each level, even when the player replays it in a different session, then PlayerPrefs may be the way to go for you.

Thank you for taking the time to share your thoughts, @ChibelD.

This is what I was considering as well, however, I believe a Singleton or PlayerPrefs is required so the script is not destroyed when the scene reloads.

Thank you for sharing your advice @Brian_Trotter.

Yes, my game is very simple. It’s project boost with 10 levels and a dialogue system that displays at the beginning of each level. As such, it sounds like a Singleton will work.

One additional question, would you then control the states with a bool as @ChibelD recommended above? Or, would you use something like a switch statement for each state?

I will continue to struggle through this. Thanks again for your feedback.

Privacy & Terms