Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Neurus_Ex · Jul 02, 2017 at 09:58 PM · animationanimatoranimationsbooleanparameters

Play animation while button is pressed fails when using boolean parameters.

All right, I got my GameObject with its animator and several states and parameters.

My "need" is making an animation play while a button is pressed (You press for X seconds the button, the animation plays for X seconds).

So, I got my "Idle state"(IS), my "Playing animation State"(PAS). The transition from IS to PAS uses a boolean parameter "buttonPressed" and the condition value is "true".

There's some code around to handle this, and when the user presses a button, the code executes Animator.SetBool("Transition", true);

So far, so good: The state jumps from IS to PAS, and the animation starts to play. The problem is that, somehow, the value of the boolean resets, executing the transition from PAS to IS, resetting the state machine and re-executing the transition from IS to PAS.

So, I'm scratching my head on what could be wrong here: Is my approach to keeping the animation playing wrong? I'm ignoring any other "right" way to do this? Should I re-check any value on the animator?

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
1
Best Answer

Answer by Elendow · Jul 03, 2017 at 09:25 PM

Hi,

Generally, the problem with "input loss" is due to check this input on the FixedUpdate. This problems appear because the input is updated at the beginning of every frame, but the FixedUpdate can be called outside that frame or multiple times in it.

The best you can do is to check the ups and downs of the input on the Update in order to have the freshly updated input values.

If doing this check in the Update is not possible, another solution is to check the "GetButton/GetKey" instead of "GetButtonDown/GetKeyDown" and "GetButtonUp/GetKeyUp". Generally this value works fine on the FixedUpdate, but not always.

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 Neurus_Ex · Jul 06, 2017 at 09:04 PM 0
Share

Well, it seems I can't use the GetButton/ButtonDown, because those need the keys to be mapped with the default "Input" system, which seems everyone suggested to not use (And given my game is for 4 players on the same computer...)

Anyway, as I got my own input controller, I switched the functions (as I got one for updates and another for fixedInputUpdates, something to do with physics and stuff), the animation played as it was supossed to do.

Thanks!

avatar image RobAnthem Neurus_Ex · Jul 06, 2017 at 09:11 PM 0
Share

You can make your own keymappings like this.

 public $$anonymous$$eyCode action$$anonymous$$ey;
 
 void Update()
 {
     if (Input.GetButtonDown(action$$anonymous$$ey))
     {
         Debug.Log("Action $$anonymous$$ey Press");
     }
 }
avatar image Neurus_Ex RobAnthem · Jul 06, 2017 at 09:22 PM 0
Share

Hey, I was editing the comment right when you answered, lol.

Input.getbuttonDown is asking me for a String parameter, not an Action$$anonymous$$ey, and when going "I'm gonna be lucky" (Using the ToString function), Unity just tells me to bind the keys on the Edit->Whatever menu, which is a nope.avi, as all our input system was written based on the suggestions of "not using Unity's default input system."

I'll see if I can do something with this. Thanks anyway!

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

165 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

Related Questions

Animator parameter stuck as True 4 Answers

Jump animation anticipation 2 Answers

Dynamically add AnimationState to Controller 0 Answers

Animations will play for a second perfectly then stop HELP 1 Answer

Pause Menu issue with mouse 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