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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Bug Bug 1279007: Input.GetKey returns false after LoadScene is called, despite held key

Discussion in 'Input System' started by dgoyette, Sep 20, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    This seems like a major bug, but all I could find were a couple of very old posts and Unity Answers pages on the topic, none of which had any reasonable solutions.

    I've reported this as bug #1279007. The gist is very simple: If you're holding down a given key when SceneManager.LoadScene() is called, Input.GetKey() will return 'false' for that key upon loading the new scene, even though the key is currently being held down. Input.GetKey() won't return 'true' for that key again until the player releases the key and presses it again.

    Note that this only happens when LoadScene is done in "Single" mode. If you use LoadScene in Additive mode, this bug does not occur. I can only guess as what's happening behind the scenes, but it's as though GetKey is checking some set of held keys that gets wiped out when a new scene is loaded.

    For anyone who wants to be able to have players hold a key during scene load, this presents a lot of complexity. It's no longer possible to do a simple LoadScene(). Instead, if you want to preserve held inputs, you need to use LoadScene in additive mode, and deal with the potentially huge complexity of having multiple scenes loaded at the same time that were never meant to be loaded simultaneously.

    A repro project is attached to #1279007 that clearly demonstrates this issue.
     
  2. YYXL_01

    YYXL_01

    Joined:
    Dec 31, 2020
    Posts:
    2
    I have the same problem.Did you solved it?
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Not directly. Per that bug report:

    In general, I also use additive scene loading to loads scenes, so this tends not to be of practical concern for me in most cases.