c# - (Unity Fishnet CSP v2) When does the replicate method get called? - Stack Overflow

admin2025-04-17  2

I have been working on learning the Unity Fishnet Client Side Prediction v2 for a while. Something that has eluded me is when the [Replicate] method is getting called. Placing a debug statement inside the replicate method shows this is getting called many times outside of the tick. So what gives? Where is this coming from? I need to know this information so I can understand how to properly reconcile.

Here is how I have things setup.

public override void OnStartNetwork() {
  base.OnStartNetwork();
            
  base.TimeManager.OnTick += TimeManager_OnTick;
  base.TimeManager.OnPostTick += TimeManager_OnPostTick;
}
public override void OnStopNetwork() {
  base.OnStopNetwork();
  base.TimeManager.OnTick -= TimeManager_OnTick;
  base.TimeManager.OnPostTick -= TimeManager_OnPostTick;
}
protected virtual void TimeManager_OnTick()
{
  Replicate(CreateReplicateData());
}
protected virtual void TimeManager_OnPostTick()
{
  CreateReconcile();
}

So this is a basic on tick setup.

[Replicate] Method extract:

[Replicate]
private void Replicate(ReplicateData data, ReplicateState state = ReplicateState.Invalid, Channel channel = Channel.Reliable)
{
...
  RunningMoveType = data.MoveType;
...
   switch(RunningMoveType)
   {
                case MovementType.RelativeCamera:
                    Move_RelativeCamera(data, state);
                    break;
                case MovementType.EnterLadder:
                    Move_EnterLadder(data, state);
                    break;
                case MovementType.Ladder:
                    Move_Ladder(data, state);
                    break;
                case MovementType.ExitLadder:
                    Move_ExitLadder(state);
                    break;
                default:
                    break;
  }
...

[Reconcile] Extract

public override void CreateReconcile()
{
  Reconcile(new ReconcileData(PredictionRigidbody, RunningMoveType, moveStage));
}
[Reconcile]
private void Reconcile(ReconcileData data, Channel channel = Channel.Unreliable)
{
   tmp = RunningMoveType;
   RunningMoveType = data.MoveType;
   PredictionRigidbody.Reconcile(data.PredictionRigidbody);
   RunningMoveType = tmp;

That isn't working. Has anyone setup ladder climbing or multiple movement states with CSPv2 and gotten it to work? My thought here is if I can understand the inner workings a lot better I can better understand how I should be designing this. Right now I have zero clue how [Replicate] is getting called outside of my OnTick method.

转载请注明原文地址:http://anycun.com/QandA/1744891094a89086.html