#how can i send rpc using server and client separately?

1 messages · Page 1 of 1 (latest)

odd bolt
#

Hey guys, i need some help with godot 4 networking, im doing server and client separate and im not been able to send a rpc from my server to all the peers connected
i have the peer_connected signal to trigger the function below on the server side:

#

and this one on my client side

#

the connection seems fine, but this rpc calls returns error 31 (ERR_INVALID_PARAMETER)
the output log:

#

thats the node structure in both server and client, is there anything wrong?

edgy laurel
#

I don't see a World node (or a World/Enemies node for that matter)

#

also get_tree() returns SceneTree, not the root node

#

for that you want to get the root property

#

doing "../" from root would be invalid, because root is already the bottom most, it doesn't have a way to go back one more

odd bolt
edgy laurel
#

try changing your get node statement to get_tree().root.get_node("World/Enemies")

odd bolt
#

on the client side, it doesnt even get to print the line 6 "spawning player"

edgy laurel
#

what do the notifications say? there should be an error message with more detail included

#

ERR_INVALID_PARAMETER is returned by rpc in the following cases:

  • The object trying to call the rpc isn't in the scene tree or is not a valid node
  • The method is missing or is not marked for RPCs in the local script
  • You're trying to RPC yourself
odd bolt
#

E 0:47:38:0292 Server.gd:25 @ _peer_connected(): Unable to get the RPC configuration for the function "spawn_player" at path: "/root/Server". This happens when the method is missing or not marked for RPCs in the local script.
<C++ Error> Condition "rpc_id == 65535" is true. Returning: ERR_INVALID_PARAMETER
<C++ Source> modules/multiplayer/scene_rpc_interface.cpp:480 @ rpcp()
<Stack Trace> Server.gd:25 @ _peer_connected()

edgy laurel
#

yeah, that's the second point

try adding

@rpc
func spawn_player(player_id, location):
  pass

to your server side Server.gd

#

and see if that works for it

odd bolt
edgy laurel
#

maybe rename the location to spawn_position

odd bolt
#

but on the other hand, on my client side it printed the line 6

edgy laurel
#

so it matches the server's version

odd bolt
#

and gave the same error

edgy laurel
#

that's the get_tree().root part

get_tree() returns SceneTree
get_tree().root returns the root node at the bottom of the scene tree (which is the one that has get_node())

odd bolt
edgy laurel
#

so long as I have the same function with the same parameters in the node on either end (and it's an @rpc on both sides), it seems to work fine here

#

(the code of the function does not have to be the same)

#

(just the name and parameters)

odd bolt
#

btw, im trying to check if the player_id is equal to the current client network id, when i doing it right if multiplayer.get_unique_id() == player_id ?