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 zach-r-d · Jul 24, 2013 at 05:56 AM · inputinput.getaxisscene load

Is it possible to work around Input.getAxis always returning 0 after scene loads?

I have a player that moves based on Input.getAxis(). When the player reaches the right edge of a scene, another scene is loaded, and the same player object (using DontDestroyOnLoad) is placed at the left edge of the next scene.

Ideally, if holding the move right button through the scene load, the player would continue moving to the right since the button was never released. While it occasionally does work, frequently Input.getAxis() will simply return 0 for the axis of the key being held after the scene load, and will continue to do so until the key is released and pressed again.

Searching for this problem yields occasional over the years since 2011, none with definitive answers, but it's been a while so I figured I'd ask again. Is there a workaround?

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

4 Replies

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

Answer by Somian · Jun 13, 2015 at 11:59 AM

How about a GameObject that gets the axis input and doesn't get destroyed when the new scene is loaded, using DontDestroyOnLoad? http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

EDIT: doesn't work, but:

Application.LoadLevelAdditive seems to work.

basically, your character/car/plane/whatever that takes the input is the first "level" and the other parts of the game world you load are loaded through Application.LoadLevelAdditive. Then the character with input should stay intact.

Comment
Add comment · Show 6 · 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 zach-r-d · Jun 13, 2015 at 12:18 PM 0
Share

Sadly, that would not work around the problem; see chris_taylor's comment on $$anonymous$$ikael's answer. As soon as the new scene is loaded, Input.GetAxis would still return 0 despite the user not releasing the key yet. Ignoring the 0 would mean the player would keep walking even after they release the key (until they pressed and released again), honoring it results in the current behavior.

avatar image Somian · Jun 13, 2015 at 12:28 PM 0
Share

And if You use Application.LoadLevelAdditive to load the new scene? :D

(kind of the inverse solution). haven't checked with getAxis yet, but I remember Application.LoadLevelAdditive being relatively smooth.

avatar image zach-r-d · Jun 13, 2015 at 12:31 PM 0
Share

From Ash Blue's link in the comments of chris_taylor's answer: http://forum.unity3d.com/threads/application-loadlevel-resets-input-getaxis-work-arounds.118511/#post-1177158

:(

avatar image Somian · Jun 13, 2015 at 12:36 PM 1
Share

ah, so that does seem to work ;)

avatar image zach-r-d · Jun 13, 2015 at 12:41 PM 0
Share

Oh wow, I should have read later posts in that thread. Thanks! If you make it an answer I'll accept it.

Show more comments
avatar image
1

Answer by chris_taylor · Jul 24, 2013 at 09:12 AM

The only thing I could think of is to write your own system with Input.GetKey. You could lerp a value to 1 and -1 based off witch key is pressed and if none is pressed lerp to 0, or any other interpolation method you want

Comment
Add comment · Show 8 · 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 Owen-Reynolds · Jul 24, 2013 at 03:31 PM 0
Share

This isn't as difficult as it sounds (don't need lerp -- can use it if you enjoy it.) And once you've done it, you start seeing new features you can add.

avatar image chris_taylor · Jul 24, 2013 at 04:42 PM 0
Share

lerp was just an example, you can just do if less than 1 add .1 or something also

avatar image zach-r-d · Jul 25, 2013 at 03:28 AM 0
Share

After some testing, it appears that Input.Get$$anonymous$$ey suffers the same problem. So promising, too!

avatar image chris_taylor · Jul 25, 2013 at 05:58 AM 0
Share

Let me do some testing ill be back hopefully with an solution

avatar image Ash-Blue · Jul 14, 2014 at 12:53 AM 1
Share

Word is that pro's async does not fix this issue (http://forum.unity3d.com/threads/application-loadlevel-resets-input-getaxis-work-arounds.118511/) and custom input does not seem to fix the issue either. As pressed inputs becomes non-readable after the level transition. I'm literally dying for a solution to this, someone please save me.

Show more comments
avatar image
0

Answer by Mikael-Gyth · Jul 24, 2013 at 09:29 AM

you could use localstorage to save state between sceneloads. something like(Pseudocode):

 onExit
 if isMoving
    savedstate = isMoving
 onLoad
    isMoving = savedstate

Not sure if it's the best way to do it, but it should atleast yield consistent results.

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 chris_taylor · Jul 24, 2013 at 09:38 AM 1
Share

Not sure if this would work. If the way he is getting input is reset to 0 and if you set a bool, is$$anonymous$$oving im gussing is a bool, then after you set is$$anonymous$$oving = savedstate it would just get set back to false unless you release the key and press again

avatar image
0

Answer by lehart · Dec 16, 2016 at 11:56 AM

I know this is an old topic but i'm having similar issues. My application loads from a 3D room into a scene setup with a Canvas, a button and a sprite - Upon the scene load nothing works, the only way to get input is if i press ESC. Once the whole app is built even pressing esc doesn't resolve the issue. My sprite is a cursor with a follow mouse input script attached, the script makes the sprite follow the mouse cursor, the default unity cursor is hidden.

Everything works fine bar this bug on sceneload, weird thing is it doesn't do it when the user clicks a button, when that scene loads up (which is a duplicate of this scene which slight button changes) it runs fine, its only transitioning from a 3D level to a level that has no 3D objects just a canvas.

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

21 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

Related Questions

How do I get a value from Input.GetAxis() ? 1 Answer

Input Dead Not Being Applied to Joystick? 0 Answers

Joystick Axis 9&10 with more than 2 gamepads 0 Answers

Quirk in Input.GetAxis 0 Answers

Dualshock Dpad "sensitivity" 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