Using Input System with Fusion

Basically it should be possible to use the Input System from Unity with Fusion without much to worry about but i can't figure out how.

In this example i use the Fusion 102 Approach but want to switch this with the Input System.

In the Fusion 102 BasicSpawner the Input is managed like this:

public void OnInput(NetworkRunner runner, NetworkInput input)
    {
        var data = new NetworkInputData();

        if (Input.GetKey(KeyCode.W))
            Debug.Log("W");
            data.direction += Vector3.forward;

        if (Input.GetKey(KeyCode.S))
            data.direction += Vector3.back;

        if (Input.GetKey(KeyCode.A))
            data.direction += Vector3.left;

        if (Input.GetKey(KeyCode.D))
            data.direction += Vector3.right;

        input.Set(data);
    }

In my old project i used the input system like this:

And Added it in the old project to my Player Prefab so i could use it in the script like this:

void OnMove(InputValue value)
    {
        moveVal = value.Get<Vector2>() * moveSpeed; //the moveSpeed as public variable to change the impact of an item.

        Debug.Log("move value = " + moveVal);
    }

Just using OnMove, OnShoot, etc etc to geht the Player Moving.

So i assumed i had to get the information out ouf moveVal into OnInput. But i don't know how.

It is important that the movable Object acts correctly in the network.

Answers

  • Fusion does not really mind the input system you use. With the new one, yes, you want to register key-presses and use them OnInput() to get them networked. How that's done is up to your project, which we don't know.

  • in this case i get a vector 2, everytime the players presses (W,A,S,D)

    yes its more of a transfer problem in this case. I know that it is doable but i couldn't find anyone using the input system with Fusion so i used the older system for the time beeing.

    its just that can't figure out how to get it basically like this:

    public void OnInput(NetworkRunner runner, NetworkInput input)
        {
            var data = new NetworkInputData();
    
            if /* function OnMove gets a Value, take that value "value.Get<Vector2>()" and use it here.
    
            input.Set(data);
        }
    

    Because in the example of the Fusion 102 tutorial i get one value for every key i press while here i trigger the function OnMove when one of the key is pressed and have to get that information correctly connected to OnInput.

  • I think this is a bit late but in case someone else Is wondering about the same thing, Now the documentation is having specific section for that for the input as whole and specifically for unity new Input system.


    https://doc.photonengine.com/en-us/fusion/current/manual/network-input

    https://doc.photonengine.com/en-us/fusion/current/manual/network-input#unity_new_input_system