Multiple scenes running in parallel

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KoBeWi

Some time ago I asked about Godot running in server mode, and didn’t get any answer, but then discovered a thing like headless Godot. Seems like it is possible to do what I wanted, but now I think about what’s the most efficient way.

My game will have it’s world divided into multiple, clustered rooms (think of Castlevania). What I want to achieve is to mirror client actions on server, so it’s easy to check and synchronize them (especially useful for collisions). HOWEVER, since not everything will happen on one scene, but in multiple rooms, I have to instance each room somehow and handle them separately. Now, my first idea was to run a Godot-server instance for each room on demand. While it seems ok, I realized that each instance will load all resources into memory, so I will have duplicates of resources loaded in multiple instances = total waste of memory. Then I thought if it’s maybe possible to run, like, multiple parallel scenes in one Godot game instance, e.g. on parallel threads. So each scene is independent and they don’t interact with each other, but still update normally.

So my question is: is it possible? I tried adding scenes directly to root, but it still stacks them on top of each other. I can’t save them into variable and call _process() manually (apparently). Is there any other way I can achieve the desired effect?

I too want to know how to make this happen – a very interesting concept! Thanks KoBeWi

koigx | 2018-03-06 19:40

:bust_in_silhouette: Reply From: KoBeWi

Seems like you just need to add a Viewport and provide it with new World2D and it will all work as desired.

var viewport = =

Credits to chrisknyfe from Redding for helping to find out about this.

What object are you adding the new viewport to in this case (that is, you’re calling add_child here. which object is doing this calling)? Additionally, do you know of any other gotchas or other problems that are expected to come up when using this? Oh, one more thing, are you doing this when running from a headless Godot instance (as you had mentioned this was related to that in your question)? If not, does this cause any problems when running with UI (e.g. the new viewport is layered on top of the original one)?

shianiawhite | 2018-04-24 00:25