- Home /
Missed Input Events with Joystick
I'm working on a game with multiple scenes, and I'm having trouble with input events for my joysticks (I'm using PS3 controllers).
I'm using button presses to change scenes, but when the scene changes, the next button press of the button used to change the scene does not register, but works fine for the rest of the scene.
So, for example, if I'm at the Start menu, I press "Start" to move to change scenes and move to another menu (say, save data select). Until I press "Start" again, Input.GetButton, Input.GetButtonDown, and Input.GetButtonUp functions WILL NOT RETURN TRUE. So if I get in game and want to pause, I'll press start, and it will do nothing - press start again and it brings up the menu.
I'm fairly certain this is a bug with Unity, as I've managed to recreate the error with relative ease in a separate project. I've tested with both keyboard and joystick input, but keyboard input does not seem to suffer from this problem. Here is the code in a sample project that can recreate the issue - the more complicated the scene is, the more likely it is to occur.
EDIT: Despite being fairly sure this is a bug with Unity, I want to see if anyone can help before I submit a bug report.
using UnityEngine;
using System.Collections;
public class SceneChanger : MonoBehaviour {
private int currentLevelIndex = 0;
private const int LEVELS_IN_BUILD = 3;
// Use this for initialization
void Start () {
}
void OnGUI()
{
GUI.TextArea(new Rect(0,0, 100, 100), "Do stuff for test purposes");
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Button1"))
{
currentLevelIndex = 0;
Application.LoadLevel(currentLevelIndex);
Debug.Log("Scene 0");
}
if(Input.GetButtonDown("Button2"))
{
currentLevelIndex = 1;
Application.LoadLevel(currentLevelIndex);
Debug.Log("Scene 1");
}
if(Input.GetButtonDown("Button3"))
{
currentLevelIndex = 2;
Application.LoadLevel(currentLevelIndex);
Debug.Log("Scene 2");
}
}
}
I'll also note that in my main project, I've tried putting calls to Input.ResetInputAxes() before and after loading the level (and by after I mean in the OnLevelWasLoaded function), but the result is the same.
For anyone who doesn't want to go through the trouble of setting up a new project with different scenes etc to test this, I've attached the sample project. Any help would be appreciated!
Also, just fyi, the input manager with this project is set up to take input from the Cross, Circle, and Start buttons on a Ps3 controller. I'm running Unity on my mac, so if you're using windows and the DS3 tool, it might register differently and you might need to adjust the input settings.
Something else interesting to note - I was fooling around with the project, and holding down any of the $$anonymous$$EYBOARD keys mapped to Button 1, 2, or 3 causes the level to be reloaded repeatedly (and as you can see, I'm using GetButtonDown(), not GetButton()) . . . hmmm
After doing some more tests, if I put my level loading in a coroutine that waits until the end of the current frame before executing, then the problem di$$anonymous$$ishes. It seems like if I press and release the button very quickly, it still occurs, but if I hold the button down and release after the new scene is done loading, I don't get the bug.
Your answer
Follow this Question
Related Questions
scripting joystick input on javascript 1 Answer
Steering Wheel / joystick GetAxis trouble 0 Answers
Application.Loadlevel taking time to load scene 1 Answer
Unity 5.3 How to load current level 3 Answers
D-Pad as Button instead of Axis 3 Answers