I pressed the "ready" button, but I received input data twice at the client . official example

Options

I pressed the "ready" button, but I received input data twice at the client. This problem was found in the official example :“ Fusion-Tanknarok”

On "OnInput(NetworkRunner runner, NetworkInput input)" Function :

if (ToggleReady)
{
   ToggleReady = false;
   _frameworkInput.Buttons |= NetworkInputData.READY;
   Debug.Log("上传Ready");
}


On "FixedUpdateNetwork" Function

if (input.IsDown(NetworkInputData.READY))
{
   Debug.Log($"player{_player.playerID}收到ready数据");
   _player.ToggleReady();
}

this is result:


Best Answer

  • Luke_Sta
    Luke_Sta admin
    Answer ✓
    Options

    The client wouldn't pick up the item twice as long as your FixedUpdateNetwork implementation is correct. The reason for that is because Fusion will rollback all the game state including your [Networked] variables and transforms etc. before it re-runs the predicted simulation.

Answers

  • Luke_Sta
    Options

    FixedUpdateNetwork can get called multiple times on the client with the same input. That's because during FixedUpdateNetwork on the client, the client is running a predicted simulation. Because the client can't predict this correctly it needs to resimulate this predicted simulation each time it receives a new snapshot from the server. During this resimulation all the predicted simulation steps are repeated with the already existing input values.

  • vimrzhang
    Options

    What should I do? For some logic, I just want to execute it once in FixedUpdateNetwork 

  • Luke_Sta
    Options

    What kind of logic are we talking about? The answer on what to do depends on what you are specifically trying to achieve.

  • vimrzhang
    Options

    For example, if I press the R button to pick up the item, and press the R button again to drop the item, because the client executes it twice, the client directly picks up the item and then drops it.

  • Luke_Sta
    Luke_Sta admin
    Answer ✓
    Options

    The client wouldn't pick up the item twice as long as your FixedUpdateNetwork implementation is correct. The reason for that is because Fusion will rollback all the game state including your [Networked] variables and transforms etc. before it re-runs the predicted simulation.

  • vimrzhang
    Options

    thank you very much