Why does only my host spawn things in multiplayer?

Godot Version

Godot 4.1.3

Question

So, i’m making a multiplayer game : it’s a sorcerer with a gun, and he uses magic bullets for his revolver : you play with your friends. The problem is that there’s a magic bullet, it spawns a rock that comes out of the ground. when the host spawns the rock, the client sees it. but when the client spawns a rock, the host doesn’t see it. what am i doing wrong ?
the bullet’s script :
EARTH has a multiplayer synchroniser

	elif bullet_type == "earth_bullet" :
		instance = EARTH.instantiate()
		instance.position = self.global_position
		get_parent().add_child(instance, true)
		mesh.visible = false
		particles.emitting = true
		await get_tree().create_timer(1.0).timeout
		queue_free()

the world scene has a multiplayer spawner, and in the autospawn there’s EARTH.
so why can only the host spawn a rock ? do you need any more informations ?
the bullet that spawns the rock is spawned by the player (the bullet is also in the autospawn of world)

1 Like

Just through a quick definition of the MultiplayerSynchronizer:

Synchronizes properties from the multiplayer authority to the remote peers.

Meaning only changes made by the server gets propagated.

I used the definition of the node as a quick answer to your question, but a deeper understanding comes from the design of the type of networking Godot implements.

Out of the box, Godot uses more of a Client-Server type of networking. This means that only the server has any authority to make changes to the world. This is very beneficial in preventing players from cheating as anything the player does with a hacked client does not actually happen unless approved and replicated by the server.

What that means for you is that instead of the client directly spawning the bullet, they must send a message to the host to spawn the bullet, and then the host will spawn the bullet, thus propagating the change.

okay i’m going to try something like that, any tips before I start ? What tool should i use ? Tell me if i’m wrong, but according to what you’re saying when the client clicks to shoot instead of shooting, it has to send a message to the host so he can spawn the bullet ?

In this context, yes.

Multiplayer is intrinsically complicated, and there are multiple ways to accomplish smooth gameplay (YouTube has several informative videos describing how different games go about it).

The simplest model is to have the player send a request packet to the server for every action the player attempts (walking, shooting, strafing, ducking, etc.), and have the server echo the response to all players (including the player that made the initial request).

There are pros and cons to all the multiplayer approaches, and there is lots to learn. There is no singular perfect technique for all situations in all games.

thanks for your help, it’s now working. The new problem is I want to use steam multiplayer lobbies and that’s a whole other problem. (I asked for help on another post)