MultiplayerSynchronizer and RefCounted

Godot Version

v4.5.stable.mono.arch_linux

Question

I happen to be using C# but this question also applies to GDScript.

My understanding is that if you want an object to pass around that’s a bit more complicated than a Dictionary, you should use RefCounted. Here’s mine.

// InputState.cs
using Godot;

[GlobalClass]
public partial class InputState : RefCounted {
    public Vector3 trans;
    public Vector3 torque;
    public float throttle;
}
# player.gd

var input_manual := InputState.new() # from keyboard
var input_automatic := InputState.new() # from autopilot

I would love to just be able to write to the RefCounted, have MultiplayerSynchronizer do it’s thing, then the server acts on the information.

Nothing I do allows input_manual to appear in the replication panel. is there some magic serialization method I’m supposed to implement? Is it just not possible? Please advise.

MultiplayerSynchronizer needs a to be @exported and a base-type, a Dictionary would work. RefCounted cannot be syncrhonized because it’s a reference being passed around, multiplayer connections do not have the same references as the host/other clients.

Godot blocks any class that inherents the Object class, like RefCounted, from being serialized and sent over as a packet. There is an option in the project settings to allow Objects but this is a security risk to do so as it exposed you to remote code injection.

You can use the custom class still but you will need to sync the individual properties of your input class with the synchronizer by building a replication config programmatically. See here for an example.