-
Notifications
You must be signed in to change notification settings - Fork 13
Automatic Member Replication
Thanks to C#'s reflection, MDReplicated
is able to detect if a value has changed and call Rset
for you automatically.
To use it, mark your Node's field or property with the [MDReplicated]
attribute. You can also set one of Godot's RPCModes (Master, Puppet, Remote, etc), but if you don't MDReplicator
will automatically set it to Puppet
for you.
By default, it uses reliable replication, but you can change that by using [MDReplicated(MDReliablity.Unreliable)]
, which is recommended if the value changes very frequently.
By default, only the network master for the node will send out updated values, unless if the member is marked with [Master]
, in which case the puppets will send values - with more than 1 puppet, this will lead to some unnecessary Rset
calls.
When a new player connects, they will receive [MDReplicated]
values a short time after connect (about 1 second).
If you wish to be notified on the client when a replicated value changes, use a custom property setter:
float _BarrelRotation = 0;
[MDReplicated]
float BarrelRotation
{
get { return _BarrelRotation; }
set
{
_BarrelRotation = value;
Barrel.Rotation = value;
}
}
See the Automatic Registration section for information on how these are populated and how you can configure that.
Note: Changes in Collection types (Array, Dictionary) are currently undetected. You can mark them [MDReplicated(RepType: MDReplicatedType.JoinInProgress)]
instead and call Rset
when you make changes. This issue is tracking a solution to this.