Using Input System with Fusion
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Fusion.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Using Input System with Fusion
camouflaged_penguin
2021-10-19 09:11:43
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.
Comments
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.
camouflaged_penguin
2021-10-21 09:41:19
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.
Gameaning_Studio
2022-10-15 17:22:47
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
Hi there,
I also tried to use the new input system and followed the tutorial that Gameaning Studio recommended:
https://doc.photonengine.com/en-us/fusion/current/manual/network-input#unity_new_input_system
This tutorial uses the script PlayerActionMap which is not included in the photon fusion sdk anymore. I would like to know what to use instead?
I tried to instanciate the input Actions of unity instead. By using
PlayerInputActions _inputActions = new PlayerInputAction()
And set my movement values with
public void OnInput(NetworkRunner runner, NetworkInput input)
{
var playerActions = _inputActions.Player
var data = new NetworkInputData();
data.movementInput = playerActions.Move.ReadValue<Vector2>();
input.Set(data);
}
My NetworkInputData looks like this:
public struct NetworkInputData : INetworkInput
{
public Vector3 movementInput;
}
This is working but only very very slow and the player movement is extremly laggy.
Is it possible to use the new input system with photon fusion?
Back to top