About Networked BUG

vimrzhang
vimrzhang
edited August 2 in Fusion

I press p or L on the client and it doesn't print the log on the host. But pressing p or L on the host is normal on the client。

    [Networked(OnChanged = nameof(TestValueChange))]
    public int testValue { get; set; }

    public static void TestValueChange(Changed<Player> player)
    {
        if (player.Behaviour)
        {
            Debug.Log(player.Behaviour.testValue + $"player {player.Behaviour.playerID}"); 
        }
    }
    
    private void Update()
    {
        if (Object.HasInputAuthority)
        {
//            Debug.Log($"Player{playerID} Local Update {Runner.Simulation.Tick}");

            if (Input.GetKeyDown(KeyCode.P))
            {
                Debug.Log("print 1");
                testValue = 1;
            }
            else if (Input.GetKeyDown(KeyCode.L))
            {
                Debug.Log("print 2");
                testValue = 2;
            }
        }
    }


Best Answer

  • Luke_Sta
    Luke_Sta
    edited August 8 Answer ✓

    A few things to note here.

    • When a client updates a [Networked] property and it has just InputAuthority that change will not be synchronized to the host or anyone else.
    • Usually you'd want to handle client inputs using NetworkInput.
    • If you want an Input to modify a Networked property you should do that in FixedUpdateNetwork so that it gets predicted on the client but also executed on the server.

    I suggest going through the Fusion 100 tutorial which explains this all in more details.

Answers

  • I am having the same issue in shared mode with a boolean, only the first player to join calls onChanged on all other clients. Other players just do it locally.

  • Luke_Sta
    Luke_Sta
    edited August 8 Answer ✓

    A few things to note here.

    • When a client updates a [Networked] property and it has just InputAuthority that change will not be synchronized to the host or anyone else.
    • Usually you'd want to handle client inputs using NetworkInput.
    • If you want an Input to modify a Networked property you should do that in FixedUpdateNetwork so that it gets predicted on the client but also executed on the server.

    I suggest going through the Fusion 100 tutorial which explains this all in more details.

  • So how to synchronize unpredictable data to host? such as motion capture ...

  • @WBBB The answer to that depends on the specific use case. I'm also not sure if I understand what you mean by unpredictable data so if you could elaborate on that, that would be helpful. Maybe to clarify some misunderstandings, prediction in this case is not about predicting future data that it is not yet available it is about having the client run the local game simulation with the inputs that are already available to it but that have not been processed yet by the server due to network latency.

    If you are talking about motion capture such as tracking hand and other body positions as input for a VR game than you can run a predicted simulation with that. In that case your NetworkInput is the hand positions and in FixedUpdateNetwork you can use those positions to run the simulation (update animation / IK positions, grab something etc.).