|Topic was automatically imported from the old Question2Answer platform.
Recently, my code gave me this error:
Attempt to remote call unexisting ID
I understand this is because the client had disconnected before the
rpc_id call. So now, i think there is a problem.
I would technically need to test if a client is still connected before every
rpc_id call if i don’t want any error, but wouldn’t that affect performances ? (especially for constantly sending important data like player position)
rpc call return an empty variant but i think it could be used to return an
Error instead, like the
But for now, what should i do ?
Store your connected peers to a dictionary or array and remove them from said storage on disconnect or use sceneTree’s
Then before an
rpc_id call do a verification check
if id in connected_peers:
rpc_id(id, "send_important_data", data)
Such a check would be in micro seconds an wouldn’t affect performance in the slightest
Wow, thank you so much for the
I was already doing the obvious method of tracking connected peers via the built-in
peer_disconnected signal callbacks, but I was STILL receiving the error because I think the callbacks weren’t happening fast enough. Many of the RPC calls I’m making are asynchronous which I think is the root cause. Combining both of these checks
id in connected_peers AND
id in get_network_connected_peers() completely eliminated the error. The former prevents logic errors (code bugs), while the latter prevents spontaneous disconnects that occur during an asynchronous RPC-calling method.
Still using Godot 3 but I couldn’t find documentation on this even after hours of reading & searching & experimenting.
knightofiam | 2023-03-11 05:33