0 votes

Hey guys,

I'm trying to make a multiplayer game. So far I have both a Server and Client code. But I recently ran into an issue, maybe cause I'm stupid? Right now, I have it so the client sends data to the server, which works just fine. Now I want the server to send data back to all clients to the server, so all clients know the positions of other clients. Is this not right?

Server code:

func update_puppets():
    rpc_unreliable("update_puppet", data, rotation_data) 

Client code:

puppet func update_puppet(puppet_data, puppet_data_rotation):
    speed = puppet_data["speed"]
    velocity = puppet_data["velocity"]
    x_delta = puppet_data_rotation["x_delta"]
    rotate_y = puppet_data_rotation["rotate_y"]

I get an error:

RPC 'update_puppet' is not allowed on node (path of the player ID) from 1. Mode is 3, master is 52950161.

in Engine by (12 points)

1 Answer

0 votes

I wrote a post, and then realized it was wrong from top to bottom (my bad)!

The problem is that you're trying to RPC to puppets from the server, while the server's version of the updated node is a puppet too. So the server ends up sending a message to itself (and all other puppets, but the point is, this is a reflexive call).

From the documentation:

enter image description here

In your game, the SERVER is the master of most things, except for players, which are "puppets" on the server. When you RPC from a puppet to a "puppet" function, you get an error, because you're sending a message to yourself.

Instead, what you want to use is either remote (to update the node on all nodes except the current one), or, if you really do want to include the server in the RPC call, you can use remotesync.

.
.
.
.
Old Post (Most of this is wrong):

Is this function in a client-owned node? If update_puppets is in the client-owned player node, you can't call RPCs on it from the server (WRONG! Shame on me). Godot has pretty strict ownership based on what nodes can call RPC functions. I think this is so different peers can't get desynchronized due to clients with conflicting claims.

To send signals to clients, you have to call an update_puppets function from a server-owned node (that assumably also exists in the clients). That function will then make calls on the client's puppets. Something like this (THIS WORKS, BUT IS ALSO COMPLETELY ROUNDABOUT AND UNNECESSARY):

# In server-owned node:
remotesync func update_puppet(path_to_puppet, puppet_data, puppet_data_rotation):
    get_node(path_to_puppet).update(puppet_data, puppet_data_rotation)
by (154 points)
edited by

I actually might be wrong on this. It looks like you might be able to call RPC on client nodes? One sec.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.