Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

How to prevent Input System actions while typing in InputField (TMP)

Discussion in 'Input System' started by rasulfazlyev, Sep 11, 2020.

  1. rasulfazlyev

    rasulfazlyev

    Joined:
    May 13, 2020
    Posts:
    2
    Hello!
    I have a game object with PlayerInput and an action on key Q. And it isn't supposed to be triggered when I type something like "qwerty" in the InputField (TMP). But it is triggered. How to prevent such behaviour? Both EventSystem and PlayerInput use the same action asset.

    I use version 2020.1.5f1
     
  2. rasulfazlyev

    rasulfazlyev

    Joined:
    May 13, 2020
    Posts:
    2
    I came to this for now. But I still don't know if there is better way
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using TMPro;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6.  
    7. public class BasicPlayer : BasicCharacter
    8. {
    9.     public TMP_InputField cheatConsoleField; // is set via Inspector
    10.  
    11.     // Start is called before the first frame update
    12.     protected override void Start()
    13.     {
    14.      
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     protected override void Update()
    19.     {
    20.     }
    21.  
    22.     public void OnQdown(InputAction.CallbackContext ctx)
    23.     {
    24.         if (cheatConsoleField.isFocused)
    25.         {
    26.             return;
    27.         }
    28.         if (ctx.performed)
    29.         {
    30.             Debug.Log("Hello World!");
    31.         }
    32.     }
    33. }
    34.  
     
  3. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    129
    I believe the current best practice for something like that is using multiple action maps and switching them on/off as necessary.
    So the Player action map would be disabled while you have the cheat console open, then when closing the cheat console you reenable the Player action map and disable the cheat console action map.