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 /
  • Help Room /
avatar image
0
Question by smking204 · May 22, 2021 at 11:12 PM · scripting problembuttonsglitchresetspacebar

Why does the space bar call a function that I didn't tell it to call?

This is such a particular problem I'm not even sure how to Google it. A phone call or chat session with Unity might be necessary, but I don't know how to get one. Here's the situation:

.

I have several simple game states that are called in various ways. As far as my code goes, they seem to be pretty seamless. I start with HomeScreen() then click a button to call StartGame(). From there, I can either die or win. If I win, YouWin() is called and clicking a button there reloads the scene from the beginning. If I die, GameOver() is called, which has two buttons: one calls HomeScreen() and the other calls StartGame().

.

The problem is that my one battle mechanic involves spamming the space bar. When I get a game over and happen to be hitting the space bar (which is often), it will usually act as though I clicked the button to call StartGame(). There is no association between the space bar and that function at all--in fact, the space bar is ONLY ever used in my code to attack enemies. Also, this only happens within a second or two of dying--if I make sure to wait a couple seconds before hitting the space bar again as a test, nothing happens and all is well.

.

Two more observations: This doesn't seem to be happening in the YouWin() state, only in the GameOver() state, which is odd because the circumstance is the same--I'm usually spamming the space bar to kill the "boss." Also, I've coded StartGame() to stop the PlayGameOverMusic() coroutine, which, if StartGame() is mistakenly called with the space bar as it seems to be, should cancel the music, since there are no loops in that coroutine and there is a 4-second OneShot that is played before the actual game over music is established.

.

I can't find any explanation for any of this. It appears to be a glitch beyond what my code is doing. It's possible that it will not be like this once the game is built and published, but I'd like to address it before that if possible.

.

Thanks so much for reading and responding!

.

Steve

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 Hellium · May 22, 2021 at 11:54 PM

UI elements can be triggered from the keyboard, for accessibility reasons I think.


If you take a look at the EventSystem gameObject in your scene, you'll see that the Standalone Input Module component defines a Submit button. When pressed, this Submit button simulates a click on the currently selectedd UI element (button / toggle / input field / ...). In your case, the button calling StartGame is most likely the selected one.


In the Input Manager, this Submit button is associated to the Return key, the Enter key and the space key, causing your issue.


Remove the space key from the Submit button in your Input Manager.

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 smking204 · May 25, 2021 at 11:47 AM 0
Share

Thanks! I'll look into this, but I actually solved it a different way. I switched "Navigation" from "Automatic" to "None" on that button and all other buttons.

Could I ask you to take a look at a different issue? It's the latest question I've posted. I'm trying to call a function in one script from a function in another script. Basically, Start() calls HomeScreen(), both of which are in my GameManager.cs, and HomeScreen() calls PlayMainMusic(), which is in my SoundManager.cs. I'm getting NullReferenceException.

Makes no sense at all to me, it's just a basic function call that works at first, then breaks later on. Then I scrap everything audio-related form my scripts and start over, and again, it works at first, then later gives the NullReference...

Would love to know what I'm doing wrong there!

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

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

UI Button Movement Problem 0 Answers

disable/enable arrow keys with button,turn 0 Answers

How to shorten this code? 2 Answers

How would i modify my current script to remove these UI buttons without killing my pause menu? 1 Answer

How to make a button control Animator animation 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