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
0
Question by harperrhett · Nov 12, 2020 at 11:28 PM · inputkeyboardpackagegamepadregistering

Unity input system only triggers once

Hi there, I recently started work on a platformer, and wanted to use the new Unity input system. Unfortunately, after setting it up, any input only triggers once, and holding down on buttons or keys does not register. It all worked with the old input system, but for some reason when I hold down a key, this is the result: alt text Ideally, as I hold down a key, the character would continue to move instead of just move a little.


As you can see, I have everything set up properly: alt text I am not using any interactions, and I am on Unity 2019.4.14 LTS.


Here is my code:

 // Move
 public void OnMove(InputAction.CallbackContext in_context) {
     // Apply horizontal movement
     float temp_movementDirection = in_context.ReadValue<float>();
     rigidBody2D.velocity = new Vector2(temp_movementDirection * speed, rigidBody2D.velocity.y);
 }


Any help would be awesome!

playerinput.png (53.2 kB)
xsqcotese2.gif (20.5 kB)
Comment
Add comment · Show 4
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 andrew-lukasik · Nov 13, 2020 at 11:20 PM 0
Share

Change Control Type to Axis

avatar image harperrhett andrew-lukasik · Nov 14, 2020 at 12:31 AM 0
Share

No luck :/ - It shouldn't make a difference anyways, since I'm getting my values by specifying the type as a float.

avatar image andrew-lukasik harperrhett · Nov 14, 2020 at 12:37 AM 0
Share

Axis is a 1d vector (float)

Show more comments

2 Replies

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

Answer by Zubzuke · Nov 14, 2020 at 12:41 AM

The Player Input component is provided for convenience and it's a mess. You should forget about it and deal with the new input system on your own, it's a world easier:

 using System.Collections;
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using UnityEngine;
 
 public class MyInputManager : MonoBehaviour
 {
     public float movementDirection = 0f;

     // this is the class associated with the action map
     private PlayerControls controls = null;
 
     private void Awake()
     {
         controls = new PlayerControls();
     }
 
     private void Start()
     {
         // setup event handlers
         controls.Gameplay.Movement.started   += Movement_started;   // key down event
         controls.Gameplay.Movement.performed += Movement_performed; // key up event
         controls.Gameplay.Movement.canceled  += Movement_canceled;  // kinda same thing as performed
     }
 
     private void OnEnable()
     {
         controls.Enable();
     }
 
     private void OnDisable()
     {
         controls.Disable();
     }
 
     private void Movement_started(UnityEngine.InputSystem.InputAction.CallbackContext obj)
     {
          movementDirection = obj.ReadValue<float>();
         //Debug.Log("Movement action started.");
     }
     private void Movement_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
     {
         //Debug.Log("Movement action performed.");
     }
     private void Movement_canceled(UnityEngine.InputSystem.InputAction.CallbackContext obj)
     {
         //Debug.Log("Movement action canceled.");
     }
 }

Comment
Add comment · Show 2 · 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 harperrhett · Nov 14, 2020 at 12:56 AM 0
Share

So, I opted for this originally, and as far as I can remember it was working (it's been a slow week), however then I found out how easily local multiplayer can be added in if I use the player input component in unison with the player input manager component, and I switched. In fact the multiplayer aspect seems to be already working, just not the crippling problem I've brought up in this thread. Do you know if there's still easy implementation for local multiplayer I can use in runtime?

But you're totally right, I should probably switch away from the player input component if possible.

avatar image Zubzuke harperrhett · Nov 14, 2020 at 01:40 AM 0
Share

You could look through the input manager package (and samples) and see what you can use for your own input manager.

But if you wanna stick to the predefined input helpers, you may have to use a bool to keep track of action status, check this thread:

https://forum.unity.com/threads/new-input-system-how-to-use-the-hold-interaction.605587/

avatar image
-1

Answer by ahsen35813 · Nov 13, 2020 at 11:36 PM

I can't help you with the GUI based coding, but I can tell you that in C#, you need to use Input.GetKey(Keycode.Example) rather than Input.GetKeyDown(Keycode.Example)

Comment
Add comment · Show 3 · 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 andrew-lukasik · Nov 13, 2020 at 11:46 PM 1
Share

he's using new input system, not old one

avatar image harperrhett andrew-lukasik · Nov 14, 2020 at 12:19 AM 0
Share

Yeah, thanks for pointing that out, everything worked with the old input system. This is the new Input System found in the package manager. I'm not using any GUI based coding...

avatar image ahsen35813 harperrhett · Nov 17, 2020 at 10:20 PM 0
Share

Oh I'm really sorry about that. I've never seen this before, so I assumed it was the new drag and drop coding system

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

245 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Gamepad and keyboard act differently in multiplayer game using Input System 0 Answers

How to find out if a button has been released (new input system/gamepad) 0 Answers

Multiple Players on one Computer/Console 5 Answers

Switching between Inputs 1 Answer

What Key do you press to "Jump" in the T_T Tutorial? 2 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