Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EricEntertaiment · May 19, 2021 at 09:30 PM · inputcontrollercallback

Input System: Input Action "started" Callback doesn't work properly on controller triggers?

Hello everyone,

I've encountered a problem with the Input System's reliability when using a controller's trigger buttons (known as LT resp. RT on XBOX controllers).

If I don't press the trigger buttons fast and strong enough (that is, down to the maximum within 1 frame), the InputAction's "started" callback function isn't being invoked. This causes a bug in my script, because I want to run different lines of code depending on whether or not the button was just pressed in the current frame. The "performed" callback function however is being invoked just as expected. So according to Unity, the InputAction is being performed but at the same time it hasn't even started yet...

The script works with keyboard keys and contoller face buttons, just not with controller trigger buttons (and yes, I tried multiple different controllers). However, I'd really like to keep the keybindings fully remappable. So can someone please explain if this is an intended behaviour? If so, any ideas for a workaround?

I attached an exemplary script down below:

 public class DemoScript : MonoBehaviour
   {
       private Input
           _input;
       private bool
           _inputCrouch,
           _inputCrouchStart,
           _inputCrouchCancel;
 
       private void OnEnable()
       {
           _input.Enable();
       }
 
       private void OnDisable()
       {
           _input.Disable();
       }
 
       private void Awake()
       {
           //set up input system
           _input = new Input();
 
           _input.ActionMap.Crouch.started += ctx => _inputCrouchStart = ctx.ReadValueAsButton();
           _input.ActionMap.Crouch.performed += ctx => _inputCrouch = ctx.ReadValueAsButton();
           _input.ActionMap.Crouch.canceled += ctx => _inputCrouch = ctx.ReadValueAsButton();
           _input.ActionMap.Crouch.canceled += ctx => _inputCrouchCancel = !ctx.ReadValueAsButton();
       }
         
       private void Update()
       {
           //not true if I just press the trigger halfway down
           //not true if I slowly press it until max
           //only true if I quickly press down to max
           if (_inputCrouchStart)
           {
               Debug.Log("inputCrouchStart is True!");
           }
 
           //true if I just press the trigger halfway down
           //and true if I slowly press it until max
           //and also true if I quickly press down to max
           if (_inputCrouch)
           {
               Debug.Log("inputCrouch is True!");
           }
             
           //invalidate both started and canceled inputs at the end of the update method
           _inputCrouchStart = false;
           _inputCrouchCancel = false;
       }
   }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by EricEntertaiment · Jun 22, 2021 at 04:01 PM

To whom it may concern, it was pointed out to me that ReadValueAsButton() won't return true if the button (trigger in this case) hasn't been pressed at least halfway within the corresponding frame, at least per default.

There are multiple ways to deal with that, the quickest being to simply axe the ctx.ReadValueAsButton() and directly do this:

_inputCrouchStart = true;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Thrustmaster wheel controller giving me weird values 0 Answers

Inputs for xbox360 controllers triggers switch from player 1 and player 2 after export 1 Answer

Gradual Speed Increase with Variable Input 0 Answers

Disabling Player Movement when inputting text? 0 Answers

Vive Controller not enabled until mouse click 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges