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 ToastedShrimp · Nov 24, 2021 at 02:48 PM · movementinputaction

New Input System 'Started' and 'Performed' actions fire at the same time?

Hey guys,

So, I'm writing a simple 2D player script with an input manager. I'm trying to have a "Started" action that fires an OnMoveStart event, and a "Performed" action that fires an OnMoveEnd event. I'm doing this so I can continuously call the OnMoveStart method via a boolean in Update so the player can hold down the forward key and stay moving. The problem seems to be that both started and performed actions are firing simultaneously, as noted by a Debug.Log. I thought 'Started' happened when the key was initially pressed, and 'Performed' happened when the key was released? Is this not the case? Is there something else I'm doing wrong? Thanks for any help. Here's the Input Manager:

.

 public class InputManager : MonoBehaviour
     {
             public static Controls inputActionAsset;
             [SerializeField] public PlayerController Player;
 
             private void OnEnable()
             {
                     inputActionAsset = new Controls();
                     inputActionAsset.Player.Move.started += Player.OnMoveStart;
                     inputActionAsset.Player.Move.performed += Player.OnMoveEnd;
 
                     inputActionAsset.Enable();
 
             }
 
             private void Update()
             {
                     if (Player.moving)
                     {
                             Player.rb.velocity = new Vector2(Player.moveSpeed * Player.multiplier, 0);
                     }
             }

.

and the PlayerController script:

.

     public class PlayerController : MonoBehaviour
     {
         public Rigidbody2D rb;
         [SerializeField] public int moveSpeed;
         public float multiplier;
         public bool moving;
         private void Awake()
         {
             rb = GetComponent<Rigidbody2D>();
         }
 
             //if the player starts the action, set the move bool to true
             //if the player performs the action, set the move bool to false
             //this move bool calls the move action in update, so if it's true, it'll keep firing
 
        public void OnMoveStart(InputAction.CallbackContext context)
        {
            multiplier = InputManager.inputActionAsset.Player.Move.ReadValue<float>();
            rb.velocity = new Vector2(moveSpeed * multiplier, 0);
            moving = true;
            Debug.Log(moving.ToString());
 
        }
 
        public void OnMoveEnd(InputAction.CallbackContext context)
        {
            moving = false;
            Debug.Log(moving.ToString());
        }
     }
 

.

there's some ugly code in here I plan on changing, like caching vectors and stuff but I'm just trying to get it to work for now.

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 JethRow · Nov 25, 2021 at 06:18 PM

Hello, I can tell you what i found out about those 2 and it has been bothering me alot too! when you are using joysticks , as i did, and for example setting "Started" for your axises for example left joystick stick, i was getting values depending on how fast i moved joystick stick, as soon as updates start it takes in that one value and it just keeps that value untill you stop interacting with stick and the "Canceled" would be called , and for "Performed" i had results that i got a value that changed while update was running depending on how much i pushed the stick, so for example on Mouse axis X for "Started" if you moved your mouse slowly to the left you would get -0.08 and if it was faster it would be up to -1 depending how fast ur hand is, and for "Performed" you would get nice values across as long cancelled is not called , i hope this helps you!

also both Started and Performed are started when the key is pressed, the difference is Started takes first value it gets from the update or whatever you are using, and performed updates those values, in order , What u think that Performed is doing is what Canceled is doing and that is what happens when u stop pressing the button, usually something like

 if (context.canceled)
         {
             Vertical = 0f;
 
         }

Cheers!

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

212 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

Related Questions

How can i edit this code to rotate my player to fixed angles when a key (or a combo of keys) is pressed? 1 Answer

Add keyboard input in ClickToMove 0 Answers

My Players speed differs depending on the input method (gamepad or keyboard) 1 Answer

New Input System for Controller is not able to work with autogenerated C# class file Unity 2018.4 0 Answers

Stop player rotation when there is no movement 1 Answer


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