May I use this approach :hide and show

I instantiate the game over scene to the UI, and hide it in the ready method,
then I show it when the player die, it looks the same with the tutorial ,but I want to know
if this is a good approach?

That’s certainly one way to do it. The short answer is, if it works, it works.

Your solution isn’t the best of habits to get into though, and there are 2 main reasons for this that I can think of:

  • Unnecessary stuff occupying memory should generally be avoided - any visual components that are hidden like this are just sitting there doing nothing, taking up resources, so they should be made when needed.
  • What if the player wins? You’ve now instantiated something that the player never needs.

You’re not always going to be writing perfect code, and having code that does what it’s supposed to is always the first priority, but it really would be better to simply instantiate the scene when you actually need it.

That said, this is a learning project; if you just want to experiment with hide() and show(), go for it (as long as you get why this isn’t the best use-case for them). If you keep this solution, you might even consider writing comments to remind future-you that this isn’t optimal. That way, you can’t mislead yourself about it.

1 Like

Thanks for answering so quickly and in such detail!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms