RPC Error due to NodePath

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cuppajoeman

Hi there,

I’ve recently been trying to learn about how multiplayer works, and started doing some tinkering on my own, so far my file structure looks like this:

.

├── client
│   ├── Client.gd
│   └── Client.tscn
 ...
└── server
    ...
    ├── Server.gd
    └── Server.tscn

Server.gd (note, the only function of interest is process_player_inputs)

extends Node

var peer = NetworkedMultiplayerENet.new()
const PORT = 5000
const MAX_PLAYERS = 500

# Called when the node enters the scene tree for the first time.
func _ready():
	start_server()
	
func start_server():
	peer.create_server(PORT, MAX_PLAYERS)
	get_tree().set_network_peer(peer)
	print("server started")
	
	peer.connect("peer_connected", self, "_peer_connected")
	peer.connect("peer_disconnected", self, "_peer_disconnected")
	
func _peer_connected(player_id):
	print("user " + str(player_id) + " connected")
	
func _peer_disconnected(player_id):
	print("user " + str(player_id) + " disconnected")
	
master func process_client_inputs(input):
	print(input)

Client.gd

extends Node

var network = NetworkedMultiplayerENet.new()
const IP_ADDRESS = "127.0.0.1"
const PORT = 5000


# Called when the node enters the scene tree for the first time.
func _ready():
	connect_to_server()
	
func connect_to_server():
	network.create_client(IP_ADDRESS, PORT)
	get_tree().set_network_peer(network)
	
	network.connect("connection_succeeded", self, "_connection_succeeded")
	network.connect("connection_failed", self, "_connection_failed")

func _connection_succeeded():
	print("connected to server")
	
func _connection_failed(player_id):
	print("failed to connect")
	
func _process(delta):
	rpc_id(1, "process_client_inputs", "got it")
	

When I run the server, then the client, we get something like this (server left, client right)

client-server-issue-image

Where the first two errors on the client side seem to be rpc requests before the network connection is initialized, and the errors on the server side seem to be coming from the rpc calls from the client.

I’ve taken a look at the documentation for rpc:

Sends a remote procedure call request for the given method to peers on the network (and locally), optionally sending all additional arguments as arguments to the method called by the RPC. The call request will only be received by nodes with the same NodePath, including the exact same node name. Behaviour depends on the RPC configuration for the given method, see rpc_config(). Methods are not exposed to RPCs by default. See also rset() and rset_config() for properties. Returns null.

After reading this part:

The call request will only be received by nodes with the same NodePath, including the exact same node name.

I know this has to be the issue, the thing is I’ve been having trouble understanding how to actually fix that up in my specific situation, and to understand the motivation behind why why we would want this to be true.

Hopefully someone can answer these two questions!