Observe in the image above that the actions JoinPlayer and OpenSettings use the same binding, Start Button [Gamepad]. What do you recommend I do in this situation? I want to use the Start Button to trigger JoinPlayer, but I also want to use the Start Button to open Settings. How will Unity know which one I want to use?
Just subscribe to the inputs under different contexts.
Or have the one input and make it do different things depending on context.
Hi Spiney,
I would be happy with examples.
I think the documentation covers plenty: Workflow Overview - Actions | Input System | 1.11.2
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.11/manual/RespondingToActions.html
Write your code to utilise certain input actions at certain times. Or, have the one input action and just register different callbacks to it at different times.
Its generally project specific how you handle this.
I did it in two ways, but when I press Start, only JoinPlayer is executed. I really don’t know how to choose which one I want to call.
- METHOD 1
private InputAction joinPlayerAction;
private InputAction openSettingsAction;
private void Start()
{
joinPlayerAction = InputSystem.actions.FindAction("JoinPlayer");
openSettingsAction = InputSystem.actions.FindAction("OpenSettings");
}
private void Update()
{
if (joinPlayerAction.WasReleasedThisFrame())
{
Debug.Log("Join Player!");
}
if (openSettingsAction.WasReleasedThisFrame())
{
Debug.Log("Open Settings Menu");
}
}
- METHOD 2
public void OnJoinPlayer(InputAction.CallbackContext context)
{
Debug.Log("Join Player!");
}
public void OnOpenSettings(InputAction.CallbackContext context)
{
Debug.Log("Open Settings!");
}
Actually, there’s no need for me to use the same key to do more than one thing. I was concerned about the use of the Submit and Cancel actions in the UI, but it’s just a matter of adjusting the First Selected field in the Event System, and that solves it.
EventSystem.current.SetSelectedGameObject(gameobjectButton);
- The Button’s OnClick understands the Submit action.
- The Event Trigger [Cancel] component, attached to the Button, understands the Cancel action.
Problem solved.