How does one use RPCs with custom_multiplayer in Godot 4?

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

Are RPCs usable yet with custom_multiplayer or am I doing something wrong?

The code is mostly from an example project for Godot 3 that I’ve modified for 4. The original worked as expected.

The error:

_on_network_peer_connected: Unable to get the RPC configuration for the function "server_msg" at path: "/root/Server". This happens when the method is not marked for RPCs.

The code:

extends Node

var _peer:ENetMultiplayerPeer

func _init():
	custom_multiplayer =
	custom_multiplayer.root_node = self
	_peer =
func _process(_delta:float):
	if custom_multiplayer.has_multiplayer_peer():

extends ""

func _ready():
	var result = _peer.create_client("",5005)
	if result == OK:
		custom_multiplayer.multiplayer_peer = _peer
func _on_connected_to_server():
	print_msg("Connected to server")
	print_msg("Connected peers: %s" % [custom_multiplayer.get_peers()])

func server_msg():
	print_msg("Server says hi")

func print_msg(msg:String):
	print("Client: %s" % [msg])

extends ""

func _ready():
	var result = _peer.create_server(5005)
	if result == OK:
		custom_multiplayer.multiplayer_peer = _peer

func _on_network_peer_connected(id:int):
	await get_tree().process_frame
	print_msg("Client %s connected" % [id])
	print_msg("Connected peers: %s" % [custom_multiplayer.get_peers()])

func client_msg():
	print_msg("Client says hi")

func print_msg(msg:String):
	print("Server: %s" % [msg])

IIRC, the net code for 4.0 is still changing, i.e. it’s a moving target. Therefore, it may be a good idea to wait on the network code until it’s finalized.

Ertain | 2021-11-18 01:33

:bust_in_silhouette: Reply From: luxroy

I have had success by putting @rpc before the functions where I use rpc_id(). In your example, I would try putting it before _on_network_peer_connected(), or moving rpc_id() to another function and putting the @rpc tag before that.