0 votes

I'm making a rogue-like game. like Binding of Isaac. As far as I know, Isaac creates a scene for each room, and when you go to the next room, you go to the next scene, and when you go to the previous room, you go to the previous scene.

Is there a way to leave the previous scene's resources as is and go to the next scene, or have the next scene go to the previous scene in the same way?


For example, the room looks like this. Should I put all the rooms in the Autoload variable?

Sorry to my horrible English.

Godot version 3.3.2
in Engine by (79 points)
edited by

1 Answer

0 votes
Best answer

if you change your scenes with change_scene methods then you can't save previous scene easily. But you can implement your own scene switching algorithm:
1. Make Main node that will act as scenes container.
2. Load your scene using load, instance and add_child methods to Main node.
3. When next scene is required, you can remove your scene from Main node using remove_child method and then repeat step 2 to get new scene going. This way you still have reference to previous room and can do anything you want with it. But always remember to queue_free nodes when you don't need them anymore, otherwise, if you lose reference to it, it will result into memory leak.

Note that this is just one of the many ways of implementing scene switching algorithms and optimal solution depends on your game.
Loading rooms into Singleton class (autoloading variable) can be very bad solution. I suggest you to avoid this approach.

by (1,650 points)
selected by

Thank you! I was trying to do it with a singleton, but I canceled it and did it differently.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.