From my Menu scene, client can join server (multiplayer)
Instead of loading scene with change_scene_to_file(), I want to use ResourceLoader
Problem is : My first player seems ok (Howerver, The multiplayerSynchronizer from one nested scene doesn’t work anymore) and then the second player joining spawn only from the view of the server and player 1. Player 2 doesn’t even see himself spawning in the game. His multiplayerSpawner doesn’t even sync. Not sure what is wrong with the code.
I put in the method “process2” the old way to load directly my scene, which is working
(it doesn’t make sens to put these line in the process method but it’s just to compare)
any idea how to fix this strange bug ?
extends Control
func _ready():
if DisplayServer.get_name() == "headless":
NetworkManager.host_game()
func _on_join():
NetworkManager.playerName=%NameInput.text
NetworkManager.join_game(%AddressInput.text)
multiplayer.connected_to_server.connect(_on_connection_success)
func _on_connection_success():
ResourceLoader.load_threaded_request(target_scene_path)
loading = true
%Loading.visible=loading
var loading = false
@export_file("*.tscn") var target_scene_path: String
var progress = []
func _process(_delta: float) :
if loading :
var status = ResourceLoader.load_threaded_get_status(target_scene_path, progress)
%Loading.value = progress[0] * 100
if status == ResourceLoader.THREAD_LOAD_LOADED:
loading = false
var new_scene = ResourceLoader.load_threaded_get(target_scene_path)
get_tree().change_scene_to_packed(new_scene)
%Loading.visible = loading
func _process2(_delta: float) :
if loading :
loading = false
get_tree().change_scene_to_file("res://scenes/Game.tscn")
EDIT/NOTE : I got the same problem when using get_tree().change_scene_to_file(“res://scenes/Game.tscn”) just after :
You are spending at least one frame where the two devices are connected, but the scene tree is totally different. At best you could threaded request the target scene before connecting, but for high level multiplayer to work you must have the same scene tree directly after the connection succeeds.
You are still spending at least one frame not in the correct scene. As soon as you connect to the server you must load the next scene, no time for progress bars.
func load_game():
var new_scene = ResourceLoader.load_threaded_get(target_scene_path)
get_tree().change_scene_to_packed(new_scene)
The synchronizers and spawners run as soon as the player joins, they both expect to modify nodes by their scene tree path, if that path doesn’t match you will get errors.
Personally I have had success making a “Session” scene which has a multiplayer spawner for the lobby scene, this is deleted once the game starts and instantiates the main game scene through the same spawner.