MultiplayerSpawner Bug

You might notice that when the game starts, the host’s player is spawned at the correct spawn point, but the client’s player is spawned at the origin.

The bug happens due to the multiplayer_authority… the server cannot set the position of the client player.

The easiest fix I could find is to set the MultiplayerSpawner.spawn_function property and use the MultiplayerSpawner.spawn() method to run code on both the client and host:

@export var player_spawner: MultiplayerSpawner

...

func _enter_tree():
	player_spawner.spawn_function = spawn_player

...

func add_player(id):
	player_spawner.spawn(id)

func spawn_player(id):
	var player_instance = player_scene.instantiate()
	player_instance.position = get_spawn_point()
	player_instance.name = str(id)
	return player_instance

8 Likes

Thanks for the solution, that worked.
However, I can’t see how they are being added to the PlayersContainer, since that line was removed, yet they are still being added to it?

Also I wonder why this fault occur in the tutorial.

Check out MultiplayerSpawner — Godot Engine (stable) documentation in English

When you call player_spawner.spawn it calls spawn_function on all peers and automatically adds it to the spawn_path

2 Likes

Thanks. I still can’t see where PlayersContainer is set as the spawn_path. Am I looking at it wrong?

Ignore me, I see it now. haha

I wasted so much time on this. Thanks for the coming up with a solution.

Boom!

Nicely done, I fussed with this for too long to admit to! Thanks a bunch. I can confirm this also works later in the lectures when we turn the player selection into an array. The only difference being in the spawn_player function as follows:

func spawn_player(id):
	var player_instance = player_scenes[next_character_index].instantiate()
	next_character_index += 1
	if next_character_index >= len(player_scenes):
		next_character_index = 0
	player_instance.position = get_spawn_point()
	player_instance.name = str(id)
	return player_instance

Thanks again, what a lifesaver!

2 Likes

This definitely needs to be addressed in the course. Bashed my head against it for longer than I’d want to admit it.

3 Likes

What I don’t understand is why it doesn’t have this problem, I’m using exactly the same version, shouldn’t it work like in the video?

Thank you this was driving me crazy!

Privacy & Terms