+2 votes

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?

in Engine by (141 points)

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

1 Answer

+3 votes
Best answer

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

var viewport = Viewport.new()
viewport.world = World2D.new()

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

by (141 points)

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)?

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 webmaster@godotengine.org with your username.