Topic was automatically imported from the old Question2Answer platform.
Asked By
RoniPerson
I want to programm a card game.
The architecture i want to use is that all game logic is handled by a server and the grafic and gui stuff by a client.
But the programm should include server and client in the same project so that evryone can start a server to play with friends.
I tried to adapt this for godot 3
But when starting a new scene tree it seems to become the active render target directly.
So I can’t start a scene tree to start the server on because the client scene tree is not rendered anymore. But the client process is still called.
In the example
scene_tree.get_root().set_as_render_target(true)
is called to do this but it seems to happen automaticly in godot 3.
I have to use seperate scene trees because one scene tree can handle one network peer for the highlevel networking.
I am trying to solve a similar problem. I’m considering submitting a feature request to somehow separate the network binding from SceneTree so it’s easier to build dedicated servers with separate listeners for each functional domain (e.g. user authentication, lobby, game play, etc). It will allow servers to be better structured, more secure, better support multiple instances, etc.
I’m interested in how you adapted the scenetree_holder example to Godot 3.2.3. Would you share that part of your code?
For all with the same problem here is how I solved it.
InitServer.gd
onready var server_tree = SceneTree.new()
func start_server():
server_tree.init()
server_tree.get_root().set_update_mode(Viewport.UPDATE_DISABLED)
# add your server scene (it needs to have the same name as the singelton which handles the client connection)
server_tree.change_scene_to(preload("res://Server/Server.tscn"))
set_process(true)
set_physics_process(true)
func _ready():
set_process(false)
set_physics_process(false)
func _process(delta):
server_tree.idle(delta)
func _physics_process(delta):
server_tree.iteration(delta)
func _exit_tree():
server_tree.finish()
To start the server call InitServer.start_server()
Inside of your Server.tscn you can start a server via the standart
get_tree().network_peer = peer
methode.
For rpc to work you have to know that the script which calls the rpc has a path. In your server scene you must have your script which handles the rpc under the same path.
So if you autoload your client manager as Networking its path is “root/Networking”. Your Server.tscn is added to the root. If you name the root node of the scene its path is “root/Networking” as well. So rpc should work.
Tell me if I misunderstood the stuff with the paths but it works for me.