Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Disastrous! Unity LoadLevel() resets my input to 0.

Discussion in 'Scripting' started by GonFreaks, Mar 8, 2015.

  1. GonFreaks

    GonFreaks

    Joined:
    Nov 18, 2014
    Posts:
    2
    Whenever I use LoadLevel() Unity resets my inputs to 0 in the next scene.

    For instance, I'm making a 2D action platformer, and when my player dies, I reload the scene.

    But when the scene is reloaded, my character stands still at the beginning of the scene without moving even if I have the run and move buttons pressed since before the reload. Even if I use the KeyDown(Keycode.[whatever]) for repeated frame updates.

    One always has to lift their fingers off the buttons and press them again to make them active.

    Any workarounds? LoadLevelAsync() is so tedious for a project of this scale it's almost impossible to go back and redo everything that way. I just dont understand why it has to reset the Input.

    It's like it uses http://docs.unity3d.com/ScriptReference/Input.ResetInputAxes.html on LoadLevel() by force. Why can't this be cached for the next scene etc? Very weird engine issue imo. Almost like a bug.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    In most use cases you want the inputs to clear between scenes. Yours is an unusual case.

    GetKey may work in this case, this will simply report if a key is down or up.
     
  3. GonFreaks

    GonFreaks

    Joined:
    Nov 18, 2014
    Posts:
    2
    Hey bro! :)

    It doesn't work at all. That was also my first go-to. I figured I could just use one of those in the Update() method to check if it's being continuously pressed (in contrast to the "down" and "up" alternative).

    Unity actually doesn't even register them as being pressed when a scene is loaded which is nothing short of super weird :) I mean, the Update() is running as it should. When I debug.log them they say both say 0.

    Code (CSharp):
    1.         float horizontalInput = Input.GetAxisRaw("Horizontal");
    2.         control = Input.GetKey (KeyCode.LeftControl);