Need help with syncing spawns

Godot Version

4.2.1

Question

In short, I’m getting the following error:

on_spawn_receive: Condition “parent->has_node(name)” is true. Returning: ERR_INVALID_DATA

For more context, this is the full story. I’m pretty new to godots multiplayer system, so any help would be appreciated. The current bugs I’m experiencing are listed below.

  1. All the clients properly sync positions with one another, but for some reason the position of the host does not sync for the clients.
  2. When the host spawns an enemy when no player has joined the host, all those enemies properly sync positions with a client that joins. However, when an enemy spawns while a client is connected to the host, the enemy just teleports to the center of the world for only the clients.

I have a feeling that both of these issues stem from some common problem because I keep getting the stated error when players and enemies spawn.

I have looked through so many forums and posts relating to this error, but all the fixes seem to be unrelated to my problem. I’ve done almost everything they suggest (when applicable, for instance adding “true” as the second argument to an add_child call), but nothing seems to work.

My scene tree looks like this:

the github for the project is here. Currently the only scripts that have network related code is player.gd, giant_vole.gd, connection_handler.gd, and meadow.gd. They’re failry straight forwad scripts, nothing super special happening. I’m currently spawning in players and enemies only on the server, and using multiplayer spawn component to sync spawns. Also, I dont use any RPC functions at the moment. Please let me know if there’s any additional useful information that I could provide.

1 Like

The first and most obvious error to me is in the setup that you have made. You should only have a single MultiPlayerSpawner Node in a scene and it should most probably be the server’s authority. When you spawn players you should do it via and RPC call to the server and do the actual add_child call on the server itself. The server will sync everything automatically to the client when you do that and add a MultiPlayerSycnronizer to each of your objects that need to be synced. But keep in mind that everything that needs network sync will need to be spawned on the server.

All of this is very well documented in the official documentation and I suggest you go and read that first and I am sure it will become clearer to you. Here is a link: High-level multiplayer — Godot Engine (stable) documentation in English

Here is also a YouTube tutorial that helped me with my multiplayer game: https://youtu.be/e0JLO_5UgQo?si=e4LpwoFgnlB06xIh

1 Like

Thanks for the feedback! I already have sync components, my issue primarily stems with spawning problems (clients sync with each other correctly). Currently I have multiple multiplayerspawner nodes, but I cant find anything saying I should only have 1 per scene tree. Also, each spawner is the servers authority as in the thing its “spawning” is only spawned by the server. Is there some other way to set a multiplayer spawners authority that I’m unfamiliar with? I have already gone through the entire video and link you sent, neither of which use the multiplayer spawner component to my knowledge. Also, I’m not sure why you must spawn players through an RPC, why not just spawn them through the peer_connected callback (of course only if you are the server), and have the multiplayer sync component take care of spawning the player across the network?

1 Like