Many games will require physics bodies to be networked, even if not controlled by players or the server.
These objects can also work along-side the new state system using code near identical to our Getting Started guide.
For the most simple example of free-moving objects you only need to remove inputs from the MoveData, and pass in default when moving.
Below is a full script example!
publicclassRigidbodySync:NetworkBehaviour{ //Input fields have been removed.publicstructMoveData:IReplicateData { //b does nothing, but parameterless ctors are not supported //in the current C# version with Unity.publicMoveData(bool b =false) { _tick =0; }privateuint _tick;publicvoidDispose() { }publicuintGetTick() => _tick;publicvoidSetTick(uint value) => _tick = value; } //The reconcile struct is unchanged from our Getting //Started example.publicstructReconcileData:IReconcileData {publicRigidbodyState RigidbodyState;publicPredictionRigidbody PredictionRigidbody;publicReconcileData(PredictionRigidbody pr) { RigidbodyState =newRigidbodyState(pr.Rigidbody); PredictionRigidbody = pr; _tick =0; }privateuint _tick;publicvoidDispose() { }publicuintGetTick() => _tick;publicvoidSetTick(uint value) => _tick = value; }publicPredictionRigidbody PredictionRigidbody =new();privatevoidAwake() {PredictionRigidbody.Initialize(GetComponent<Rigidbody>()); } //In this example we do not need to use OnTick, only OnPostTick. //Because input is not processed on this object you only //need to pass in default for Move, which can safely //be done in OnPostTick.publicoverridevoidOnStartNetwork() { base.TimeManager.OnPostTick+= TimeManager_OnPostTick; }publicoverridevoidOnStopNetwork() { base.TimeManager.OnPostTick-= TimeManager_OnPostTick; }privatevoidTimeManager_OnPostTick() {Move(default);/* The base.IsServer check is not required but does save a little * performance by not building the reconcileData if not server. */if (IsServerInitialized) {ReconcileData rd =newReconcileData(PredictionRigidbody);Reconciliation(rd); } } [Replicate]privatevoidMove(MoveData md,ReplicateState state =ReplicateState.Invalid,Channel channel =Channel.Unreliable) { //If this object is free-moving and uncontrolled then there is no logic. //Just let physics do it's thing. } //This method is unchanged. [Reconcile]privatevoidReconciliation(ReconcileData rd,Channel channel =Channel.Unreliable) {Rigidbody rb =PredictionRigidbody.Rigidbody;rb.SetState(rd.RigidbodyState);PredictionRigidbody.Reconcile(rd.PredictionRigidbody); }}