I’m learning the new Input System and I decided to go the “C# events” route because I’m trying to get used to using c# events to reduce my spaghetti code. So I had it auto-generate the c# code and called it BirdActionsClass. I like that it creates properties for all the actions and maps, but I ran into a problem with multiple players. If I do something like this (I’m using polling for simplicity here):
BirdActionsClass BirdActions = new BirdActionsClass();
if (BirdActions.Playing.Flap.ReadValue<float>() >.8f)
Flap();
then Flap() is called on all players, such that they all flap when one person presses the button.
If I poll the same action on a player’s PlayerInput component, then it only reads the control scheme bound to that player, but I have to use PlayerInput.actions. FindActionMap("Playing").Find("Flap") to get the action by it’s name, which uses strings, which seems like bad form.
Alternatively, I can use BirdActionsClass to get the id of an action and then use the PlayerInput to get the action with the binding for that particular player (Edit: oops, that does not get a reference to a multiplayer-friendly action. It detects input from all controllers):
BirdActionClass BirdActions=new BirdActionClass();
PlayerInput MyPlayerInput== GetComponent<PlayerInput>();
ActionMap PlayingMap = MyPlayerInput.currentActionMap;
InputAction FlapAction = PlayingMap.FindAction(BirdActions.Playing.Flap);
if (FlapAction.triggered)
Flap();
But I doubt this is how it’s meant to be used. Does anyone know how the auto-generated c# script is supposed to work in this case? Is there any documentation for it?