Godot 4.2 - Add a property on MultiplayerSyncho

Godot Version

4.2

Question

Well guys, I posted this question on the godot discord, but as you can imagine; without many results :/. Well, the question is this, I need to add a property to the Multiplayersynchonizer by script. What is the function if there is a way to do this?

Export the property.

Hmm? Is there a way to do this? as ?

You can try using MultiplayerSynchronizer.replication_config to get the SceneReplicationConfig and do any modifications with it.

1 Like

Hmm… I actually took a look at this in the documentation. But, I wanted to know, my game is like a multiplayer FPS. When one player shoots, another player does not see the shot. Well, that’s probably because it’s not syncing the instance. In short, how to synchronize this instance, or a variable?

MultiplayerSpawner? I think you may need something more than this depending on the setup.

For everybody who is looking for answer in the future. For Godot 4.3 + C# (similar with GDScript)

[Export] public string ActiveWeapon = "WeaponName";
private MultiplayerSynchronizer ActiveWeaponSynchronizer;

public void Initialize() {
        ActiveWeaponSynchronizer = this.InstantiateAndAddAsChild<MultiplayerSynchronizer ("ActiveWeaponSynchronizer");
        
        var config = new SceneReplicationConfig();
        config.AddProperty(".:ActiveWeapon");
        config.PropertySetReplicationMode(".:ActiveWeapon", SceneReplicationConfig.ReplicationMode.OnChange);
        ActiveWeaponSynchronizer.ReplicationConfig = config;
        // .. more code below

where
InstantiateAndAddAsChild simply instantiates node and adds it as child to current node.

Please note that Node path is messed up or I don’t understand it. But with hierarchy like that

NodeThatExecutesCode
→ MultiplayerSynchronizer

path is NOT ..:ActiveWeapon but for some reason .:ActiveWeapon