Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by JesterHere · Jul 03, 2020 at 11:38 PM · inputbuttongamepad

Gamepad press and release in Input Action - UI Buttons

Hi!

I am currently implementing the UI for my game and I'm hoping to keep it cross platform. One thing I'm missing when using gamepads is the pressed and released states for UI Buttons.

I am using the Input Actions system. My hope is that when a button is selected, I would hold the gamepad button down and the UI button should enter the pressed state. Once the gamepad button is released the submit event should be activated, resulting in the button's action being activated.

Currently the submit event is activated when the gamepad button is pressed (not released)

I have tried adding an Interaction for the Press type and that the behaviour to Release Only. But this resulted in the submit event never being fired.

Could anyone point me in the right direction?

Thanks, Joe

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

Answer by jhubbard0221 · Jul 17, 2020 at 05:32 PM

It looks like you'll want to use the .performed and the .canceled functions. These allow the pressing and releasing of the buttons to have their own functions.

Here's an example using a character controller component:

 public class PlayerController : MonoBehaviour
 {
     {
         PlayerControls controls;
 
         public float movementSpeed = 7f;
     }
 
     void Awake()
     {
         controls.Gameplay.Run.performed += ctx => Run();
         controls.Gameplay.Run.canceled += ctx => Walk();
     }
 
     void Run()
     {
         movementSpeed = 14f;
         Debug.Log("Runnin");
     }
 
     void Walk()
     {
         movementSpeed = 7f;
         Debug.Log("Walkin");
     }
 
     void OnEnable()
     {
         controls.Gameplay.Enable();
     }
 
     void OnDisable()
     {
         controls.Gameplay.Disable();
     }
 }

This script would allow you go faster with the button pressed and revert back to original speed once in is released. Anything can be put in the .performed or .canceled functions, this is just my example. To you should be able to put your Submit event in the .canceled function.

Comment
Add comment · Show 1 · 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
avatar image JesterHere · Jul 17, 2020 at 07:25 PM 0
Share

I'm wondering more specifically if this is possible through the Input Action system and the ui button component that is supplied with the engine. The button component subscribes to the Submit event, and i suspect that should be able to configure the Input Actions system to only send that event on gamepad button release

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

183 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 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

Find out if any Button on any Gamepad has been pressed and which one 6 Answers

Help with a button 1 Answer

How do I fix unity game not working correctly with a controller if it is plugged in before the game starts? 0 Answers

Creating a menu for gamepad? 1 Answer

Unity Editor swallows gamepad input 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