Topic was automatically imported from the old Question2Answer platform.
Asked By
Legorel
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 everyrpc_id call if i don’t want any error, but wouldn’t that affect performances ? (especially for constantly sending important data like player position)
All rpc call return an empty variant but i think it could be used to return an Error instead, like the File object.
Store your connected peers to a dictionary or array and remove them from said storage on disconnect or use sceneTree’s get_network_connected_peers()
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 get_network_connected_peers() recommendation!
I was already doing the obvious method of tracking connected peers via the built-in peer_disconnected / 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.