godot: RPCs must be echoed in child class, otherwise they don't work.
Godot version
4.1.1.stable
System information
Windows 11 10.0.22621 Build 22621
Issue description
Currently experiencing an issue with RPCs and inheritance.
In the parent class, I have the following code:
@rpc("any_peer", "call_local")
func Sync_addImpulse(swingImpulseString : String):
if multiplayer.get_remote_sender_id() == 0:
rpc("Sync_addImpulse", swingImpulseString)
else:
var swingImpulse = JsonSingleton.parseVector2FromString(swingImpulseString)
addImpulse(swingImpulse)
When I call Sync_addImpulse in the child class, the function is called (e.g., it forwards teh RPC). However, the RPC isn’t received.
To fix, this, I simply echoed the call in the child as follows:
@rpc("call_local", "any_peer")
func Sync_addImpulse(impulse): super.Sync_addImpulse(impulse)
Strangely, it now works as expected. It seems like maybe the rpc tag isn’t inherited by the child, but that’s just a wild guess.
Let me know if you have any questions or if I can help at all.
Steps to reproduce
- Create a parent & child class
- Create some method CallRPC() in the parent class, that echoes an RPC to itself (like the one I provided)
- Call the CallRPC() method from the child class. The parent class will run CallRPC(), but it won’t receive the self-echoed RPC.
- Then, echo the CallRPC() function in the child class. You will observe that now the RPCs are received.
Minimal reproduction project
N/A - quite trivial.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 20 (7 by maintainers)
Changing filenames is currently definitely associated with funky behavior! Godot caches information about which file defines each GDScript global class name. I’ve seen a few reports that renaming files (particularly
.gdones) results in that cache becoming invalid, and strange behavior results!If you suspect this is the issue, maybe try renaming some files like how you might’ve done it originally? It would be nice to have a method to reproduce that kind of bad behavior so we can fix it also 😃
Please do not bump without adding any additional information, it is not forgotten
@AThousandShips thanks for fixing it, appreciate that