Unable to do an `rpc` with a function that uses arguments annotated with an typed Array
Godot version
Godot_v4.0-beta6_win64
System information
Windows 11
Issue description
Godot gives me an error when I try to execute an rpc function that has an argument annotated as Array[int], but it works fine when I remove the type annotation or change it to just Array. The data I'm sending is an Array[int].
This is the code of the function (it doesn't work when it has the argument type annotation):
@rpc
func client_print_array(host_array: Array[int]):
print("Host array: ", host_array)
print("My array: ", self.array)
When I try to trigger the rpc from the host it gives me this error:
E 0:00:04:0771 _process_rpc: RPC - 'Node(Main.gd)::client_print_array': Cannot convert argument 1 from Array to Array
<C++ Source> modules/multiplayer/scene_rpc_interface.cpp:294 @ _process_rpc()
Removing the annotation fixes the problem.
Steps to reproduce
- Open the Minimal reproduction project
- Run the projects as 2 instances
- In the first instance press "Host"
- In the second instance press "Join"
- In the first (host) instance press "Send message"
- Observe errors in the debugger.
E 0:00:04:0771 _process_rpc: RPC - 'Node(Main.gd)::client_print_array': Cannot convert argument 1 from Array to Array
<C++ Source> modules/multiplayer/scene_rpc_interface.cpp:294 @ _process_rpc()
- Modify the
Main.gdscript by removing type annotation on line 28 - Repeat steps 1-5
- Observe expected messages in the log output
Host array: [1, 2, 3, 4]
My array: [4, 3, 2, 1]
Minimal reproduction project
Can confirm this is still hapening on 4.1, windows
4.1 hasn't been released, can you be more explicit?
4.1 hasn't been released, can you be more explicit?
Sorry, the commit is 8d501a2dc31f3bef6d5a7f6b0d060c8915082011
I think the reason is the same as #76841: binary serialization does not currently support typed arrays, so type information is lost in multiplayer.
Text serialization:
https://github.com/godotengine/godot/blob/eb86dabee07e8dfce3b06cbd557b50b74afd3d6c/core/variant/variant_parser.cpp#L1927-L1958
Binary serialization:
https://github.com/godotengine/godot/blob/eb86dabee07e8dfce3b06cbd557b50b74afd3d6c/core/io/marshalls.cpp#L1590-L1609
@dalexeev , @akien-mga , I can still reproduce this one on v4.2.
This is causing an error:
@rpc("call_remote", "any_peer", "reliable")
func characterclasscomponent_sync_class_change(n: String, c: Array[String]):
E 0:00:29:0132 _process_rpc: RPC - 'Node(sync.gd)::characterclasscomponent_sync_class_change': Cannot convert argument 2 from Array to Array
<C++ Source> modules/multiplayer/scene_rpc_interface.cpp:290 @ _process_rpc()