Unable to Spawn bullet/children of player in network game

Godot Version

Godot v4.3dev6

Question

I’m trying to learn Network Multiplayer gaming with Godot. I’ve watch tutorials and read documentation. I almost have a very basic setup running, but I’m having issues spawning bullets across the network. I’m sure I’m just missing something small. Here is a video demonstrating the problem and a link to the project.

Source Code:

can you try to put “call_local” in the rpc aswell?

@rpc("any_peer", "call_local")

That is actually what I originally had. I removed it at some point. I just double checked and it still makes no difference.

Just realized you are not even calling the rpc:

shoot.rpc()

This is how you are supposed to call rpc’s.
Also you are using rpcs wrong. I would suggest to change the code to this:

func _physics_process(delta: float) -> void:
	if !is_multiplayer_authority():
		return

	if Input.is_action_just_pressed("ui_accept"):
		shoot.rpc()
	...



@rpc(...)
func shoot():
	var bullet = bullets.instantiate()
	bullet.position = position
	#get_tree().root.add_child(bullet)
	get_node("/root/main/spawn_point").add_child(bullet, true)

Your way would have checked on the other pc’s if they have pressed “ui_accept”, but you want to only check it for the player that wants to shoot and then call the shooting logic on the other peers.

you can also just disable physics_process for other players:

func _ready():
	if not is_multiplayer_authority():
		set_physics_process(false)
1 Like

herrspaten, you are my hero of the day!
That seems to be working. I knew it was going to be something small.
I had tried

rpc(“shoot”)

But I hadn’t seen

shoot.rpc()

I made the changes you suggested and it seems to be working.
Thank you so much!

1 Like