godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.14k stars 21.19k forks source link

multiplayer.get_remote_sender_id() Why 0? #75818

Closed zuiaiyangyang3 closed 1 year ago

zuiaiyangyang3 commented 1 year ago

Godot version

4.0.2

System information

win10

Issue description

image

In RPC.

Server and client. The server knows that the client is 919395789. Why client RPC_ID 1. Multiplayer.get_remote_sender_id () on the server. It's a "0".

But its "rpc_id (sender id)" can interact with the corresponding client correctly.

Shouldn't the server return "919395789" with "multiplayer.get_remote_sender_id ()"?

Steps to reproduce

1

Minimal reproduction project

1

zuiaiyangyang3 commented 1 year ago

222

mhilbrunner commented 1 year ago

Hey! Thanks for reporting. I could not reproduce this using Godot 4.0.2 and ENet multiplayer on Windows 10 with this test function:

@rpc("any_peer", "reliable", "call_remote")
func _test():
    var 中文假字生成器id = multiplayer.get_remote_sender_id()
    print("中文假字生成器id[%s]中文假字生成器id" % [中文假字生成器id])

(Do not mind the text, I copied the first result for "chinese lorem ipsum" from Google and hope it's inoffensive, I was trying to make sure it is not an encoding/GDScript parsing issue. Changing the function name to chinese doesn't break it either.)

That always reported 1 for the server and the peer ID 101626451 for the peer correctly. multiplayer.get_remote_sender_id() should as far as I can tell only return 0 if called outside a RPC function or maybe if not connected.

Are you using ENet or another peer type? Can you try to create a minimal reproduction project for your issue to post here?

AThousandShips commented 1 year ago

(it just says "Chinese fake character generator" 😆)

dev-mico commented 1 year ago

possible that this is caused by just calling the RPC function directly, instead of through rpc(). can you check this is not the case?

Faless commented 1 year ago

Closing as there is no reply, and this is likely caused by calling the function directly instead of via .rpc(), or it is the call_local path of the RPC itself.