Need help with spawning objects on all peers

Godot Version

Godot 4.4

Question

Hey guys, im very new to multiplayer and im using SteamMultiplayerPeer P2P for my game alongside high-level multiplayer API. So im trying to test things out to learn and im facing a problem.

To begin, im trying to learn how to spawn things and how MultiplayerSpawner works. I want to just press a button to spawn an object Infront of the player (item drop kinda thingy)

What I did is working on the host, but for the client that joins, when I try spawn an object, it spawns but snaps back and disappears plus when the client spawn the object the host cant see it, after a little bit I start getting this error a lot in yellow and the host starts lagging hard for the client.

Error:

ConnectionData::sendPending: Send error! Unreliable, won't retry. EResult 25, refer to Main class in docs.

Here is how i have it set up, not sure what im doing wrong or if this is even right to begin with.

Player Script:

@export var character_model: Node3D
@export var item_drop_scene: PackedScene
@export var items_path: Node3D

func _unhandled_input(event: InputEvent) -> void:
    if not is_multiplayer_authority(): return
    
    if Input.is_action_just_pressed("inventory"):
        drop_item.rpc()

@rpc("any_peer", "call_local", "reliable")
func drop_item():
    if is_multiplayer_authority():
        var item_drop = item_drop_scene.instantiate()
            
        var player_direction = character_model.global_transform.basis.z * 2 + Vector3(0, 2, 0)
            
        item_drop.position = global_position + player_direction
        items_path.add_child(item_drop, true)

This is also how I have it set up inside player node, obvs theres a lot I didnt show like Camera, etc. Those arent part of the problem.

I do have MultiplayerSynchronizer inside the object im spawning syncing the position of it self on spawn and always replicated.

Any help would literally save me, Ive been on this for days and I cant figure it out, I just want to work on my game and its really demotivating lol :frowning:

This isn’t really an answer to your question, but multiplayer is HARD. I highly recommend this course: Godot 4 Multiplayer: Make Your Own Online Game | GameDev.tv It is currently $13 and will help you create a fully multiplayer 2-person game. There are SO MANY concepts you need to understand, and this is the best tutorial I’ve found on them. I really enjoyed it and found it super helpful.


As to your question, you’re showing us the wrong thing. You need to show us the item you are spawning and what settings are on its MultiplayerSynchronizer.

First, thanks soo much for the course, I was actually looking for one so this would be helpful.

I fixed it by the way literally just now, but If you have knowledge on this, can you explain why?
So I removed the is_multiplayer_authority(): from the drop_item() function where the rpc is on just like shown above and only have it be called in unhandled_input so now its doing the check once.

Also here is the MultiplayerSynchronizer inside the item im spawning. Let me know if I missed a screenshot :slight_smile:

1 Like

Yes, I can explain it.

When you check is_multiplayer_authority() in unhandled_input() you are saying, "Only allow the server to create a new object by pressing the inventory action.

When you check is_multiplayer_authority() in drop_item() you are saying, “Only drop this item on the server - it should not be visible to any other multiplayer peer.”

Thanks a lot, really helpful, that was the problem that I also had.

Another thing, if you know, so I have a MultiplayerSpawner inside the player with a spawn path and a scene of the item_drop in auto spawn list with the mindset of that getting synced with the help of MultiplayerSpawner, the thing is, I tried to remove MultiplayerSpawner and it still worked, the RPC call did the job, so is there a point of keeping that?

1 Like

It depends on what you’re trying to do. But if the RPC works for you, that’s fine. MultiplayerSpawner just makes things a bit easier. For example, creating a spot in the node tree where the items will be attached, limiting the number of items being spawned, and if you like, allowing you to create a list of multiple scenes to spawn.

got it, thanks for the help and for the course, I just bought it!

1 Like

Enjoy! I’ve gotten a lot out of all their courses, especially the Blender ones. Really high quality IMO.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.