0 votes

How do I tell if a function call originated from a local method or remote call?

I have a remote function that I want to call from both sources and execute a different code branch accordingly. Current solution is to have another variable to declare if the call is local when making the call, but it doesn't translate well if I use remotesync function.

Godot version 3.4 beta 4
in Engine by (17 points)

1 Answer

0 votes

Hi
this functions of the multiplayer api should help

get_network_unique_id ( ) 
get_rpc_sender_id ( )  

https://docs.godotengine.org/en/stable/classes/class_multiplayerapi.html#class-multiplayerapi-method-get-network-unique-id

the documentation states:

Returns the sender's peer ID for the RPC currently being executed.
Note: If not inside an RPC this method will return 0.

But i dont know if it return 0 when its an remotesync but called localy ... if not you can compare the sender id to the network unique id

by (3,930 points)
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.