Spawn positions not syncing

For some reason, spawning a new player by adding it to the player container with add_child() will not sync properly for me. On the host screen you can see that both players end up in the right position for a split second. But as soon as the other player sets multiplayer authority, one of the character ends up at (0,0).

There is something going on here where the player gets instantiated on the client side with default parameters. And since the client has authority over it’s own player, the default position is what will get synced in the end.

I had to spawn the players using the MultiplayerSpawner spawner function instead. Basically set the spawner_function callback to the add_player function (which I modified to return the player)

# changes to level script

@export var player_spawner: MultiplayerSpawner

func _enter_tree():
	player_spawner.spawn_function = add_player

func _ready():
	if multiplayer.is_server():
		for id in multiplayer.get_peers():
			player_spawner.spawn(id)
		player_spawner.spawn(1)

		multiplayer.peer_disconnected.connect(delete_player)

func add_player(id):
	var player = player_scene.instantiate()
	player.name = str(id)
	player.position = get_spawn_point()
	return player

Privacy & Terms