godot icon indicating copy to clipboard operation
godot copied to clipboard

Unable to do an `rpc` with a function that uses arguments annotated with an typed Array

Open Nusiq opened this issue 3 years ago • 3 comments

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

  1. Open the Minimal reproduction project
  2. Run the projects as 2 instances
  3. In the first instance press "Host"
  4. In the second instance press "Join"
  5. In the first (host) instance press "Send message"
  6. 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()
  1. Modify the Main.gd script by removing type annotation on line 28
  2. Repeat steps 1-5
  3. Observe expected messages in the log output
Host array: [1, 2, 3, 4]
My array: [4, 3, 2, 1]

Minimal reproduction project

RpcIntArrayIssueExample.zip

Nusiq avatar Nov 26 '22 14:11 Nusiq

Can confirm this is still hapening on 4.1, windows

ShlomiRex avatar Mar 10 '23 11:03 ShlomiRex

4.1 hasn't been released, can you be more explicit?

akien-mga avatar Mar 10 '23 11:03 akien-mga

4.1 hasn't been released, can you be more explicit?

Sorry, the commit is 8d501a2dc31f3bef6d5a7f6b0d060c8915082011

ShlomiRex avatar Mar 10 '23 17:03 ShlomiRex

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 avatar Jun 14 '23 06:06 dalexeev

@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()

jonathaneeckhout avatar Dec 11 '23 09:12 jonathaneeckhout