Godot Engine

Godot Engine

なかの31 Apr 21, 2024 @ 5:25pm
Godot Multiplayer. Errors when spawning other player characters.
I'm having a issue that is burning my head, even more since the error message itself is cryptic.

I'm doing the host and join part of the multiplayer, but one of the instances of the game (probably the one where joins the server) gives the following error:
E 0:00:05:0114 on_spawn_receive: Condition "parent->has_node(name)" is true. Returning: ERR_INVALID_DATA <C++ Source> modules/multiplayer/scene_replication_interface.cpp:604 @ on_spawn_receive()

Based on part of the error, it gives the impression that there's an object with repeated name being set on a node, but I checked the scripts, and also did some debug message checking and, the clients themselves doesn't seems to be trying to spawn repeated objects, based on what debug messages returns (each call on the character spawning script happens once per client object on the clients).

This is my character spawning script. I thought it was the "call_defered" that could be causing the issue, but that causes another issue to happen, where the character isn't spawned in the right place (???).
func AddPlayer(ID): #print_debug(str(multiplayer.get_unique_id()) + "| Creating Player ID " + str(ID)) var NewPlayer : PlayerScript = SpawnPlayerCharacter(Global.SpawnX, Global.SpawnY, ID) return NewPlayer func SpawnPlayerCharacter(X, Y, ID) -> PlayerScript: var NewCharacter : PlayerScript = load("res://Objects/player.tscn").instantiate() NewCharacter.WhoAmI = ID NewCharacter.name = "ID" + str(ID) PlayersContainer.call_deferred("add_child", NewCharacter) NewCharacter.Teleport(X, Y) return NewCharacter

Other than that, on both clients, the character of the players spawns on the game world, but no sync or rpc calls happens.

Any clues of what I might be doing wrong? I'm literally running in circles about this issue...
Last edited by なかの31; Apr 21, 2024 @ 5:25pm
Originally posted by Romløk:
Is the "when a player connects" guarded by an `is_server()` check of some variety? Eg. If you're just listening for `multiplayer.peer_connected`, then clients will get that for the server's peer too.
< >
Showing 1-8 of 8 comments
Romløk Apr 21, 2024 @ 11:28pm 
That error message indicates that the client is receiving a node to spawn from the server, but the spawning fails because there's already a node with that name. Are you creating the Player on the client as well as on the server? When does AddPlayer get called?
なかの31 Apr 22, 2024 @ 12:25am 
AddPlayer is called right after server starts hosting, and also when a player connects.
The author of this thread has indicated that this post answers the original topic.
Romløk Apr 22, 2024 @ 4:15am 
Is the "when a player connects" guarded by an `is_server()` check of some variety? Eg. If you're just listening for `multiplayer.peer_connected`, then clients will get that for the server's peer too.
なかの31 Apr 22, 2024 @ 11:23am 
Nope. That's called for both servers and clients?
なかの31 Apr 22, 2024 @ 11:48am 
I added a "is_server()" check to player connect, and now it no longer show errors once other player enters server :).

Thanks. I guess better I add a comment to a 3 minute video saying how to make a multiplayer game heh.
Romløk Apr 23, 2024 @ 1:17am 
Yeah, every instance is a "peer", including the server, so peer_connected signals get fired for everyone. And by default the server will propagate other peer information too, so every peer would get a peer_connected for every other peer except themselves!

Godot networking can be confusing sometimes. It feels like a somewhat muddled bag of client-server concepts and peer-to-peer concepts, all kinda mixed together and stretched across multiple objects and APIs. :/
なかの31 Apr 23, 2024 @ 8:12am 
I actually find it a bit confusing. I've been reading documentations and am being unable to get the grasp of how it works.
I'm even having troubles getting rpcs to work. They seem to only fire locally.
なかの31 Apr 26, 2024 @ 10:37pm 
I think I got it. When calling a rpc method, lets say, move(position):, instead of calling it like "move(position)", must call it like "move.rpc(position)" instead. Like, with the ".rpc" next to the method, and with a parenthesis with the arguments of the method.

I only found out about that after checking a documentation about scene replication.
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Apr 21, 2024 @ 5:25pm
Posts: 8