Continuing process between scenes

Godot Version

4.6.1

Question

I'm a pretty beginner programmer with godot and I'm trying to make a sort of factory game. I currently have an autoload set up to hold my game data, but I'm not really sure how to approach processing the factories between scenes. To simplify my project, in scene A, a factory can be set up to produce 1 currency a minute. Later I want to be able to switch to scene B but also still be continuing to produce that currency. Right now if I switch between the scenes, the production is completely halted. I thought about using the autoload to run this process, but to my understanding that is not what should be used. I'm wondering if there's any good way to do something like this or if I should rethink some of my game structure instead.

i’m not very experienced in godot yet but I think you could use the Time singleton to get the exact time at which one scene is exited and when you come back to it, you check if there was a saved time (the exit time)

If there is, use the current time to calculate how much it should have produced (something like : you exited the Scene at 14h30 and came back to it at 15h03 so you should have produced 33 minutes worth of currencies)

Why not?

I would like it to continue to process I’m the other scene, so the values would continue to increase even while the scene isn’t active. I could see how it would work with a time singleton but I’m not sure that’s exactly what I’m going for.

I thought autoloads were more for holding global variables that are loaded oat the beginning and less for constant calculations.

Autoloads are persistent nodes. Use them whenever you need persistent node functionality in the scene tree. Your use case sounds like a good candidate.

The other approach is to not swap scenes at all but instantiate new stuff and add it as branches of the main scene.

Ultimately those two approaches result in basically the same thing at runtime.

2 Likes

the thing is you don’t have to make those constant calculations ! by using the time you exited this scene to simulate that it kept on producing when you didn’t have this scene opened, it’s more or less the same for the player

1 Like

Just reparent the machines you want in the new scene to the new scene.

1 Like

Thanks for the suggestions! I will try them out and see what works best. :+1: