Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High level multiplayer documentation doesn't explicitly explain RPC only works on methods of a Node derived class #89981

Open
iiMidknightii opened this issue Mar 28, 2024 · 2 comments

Comments

@iiMidknightii
Copy link
Contributor

Tested versions

Currently using v4.2.stable.official [46dc277]

System information

Godot v4.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 Ti (NVIDIA; 31.0.15.5186) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)

Issue description

GDScript allows you to place an RPC annotation on any method of any class you create, whether or not it is derived from Node. You can get as far as running the project and hitting the line for the defined RPC call. When the call is attempted, a run-time error informs you that RPC calls can only be made on methods of Node-based classes. This makes sense, but the documentation and script parsing isn't as explicit. The documentation mentions Nodes often in the high-level multiplayer tutorial, but there is no explicit warning that attempting to call RPC on a non-Node method is not supported. Likewise, you could code an entire interface around Resource-based RPC calls only to find out it isn't supported later during testing.

Steps to reproduce

Create any non-Node class and define a method as @rpc. Use a Node to establish a high-level multiplayer connection, then attempt to rpc() that method. You will get a run-time error, despite the documentation never explicitly stating that would happen and the script parser allowing it.

Minimal reproduction project (MRP)

bad_rpc.zip
You'll have to run test.tscn and test2.tcsn on separate Godot instances. The only indication that you can't call the rpc is a run-time error.

@AThousandShips
Copy link
Member

AThousandShips commented Mar 28, 2024

It does though, but could be more clear:

For a remote call to be successful, the sending and receiving node need to have the same NodePath, which means they must have the same name. When using add_child() for nodes which are expected to use RPCs, set the argument force_readable_name to true.

And:

Each node has a multiplayer property, which is a reference to the MultiplayerAPI instance configured for it by the scene tree. Initially, every node is configured with the same default MultiplayerAPI object.

You also have the annotation documentation that talks about nodes

@AThousandShips
Copy link
Member

We could see about adding a check for this annotation in GDScript to throw an error if its in a script that's explicitly not a node, but it might not necessarily be wrong to add the annotation to a generic script, it would depend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants