Controls problem

I’ve got a game working (what I’ve made so far at least). I can move the ship around, and it shoots.
However, when I close down Unity, the next time I bring it up, it won’t accept controls from my 360 controller (what I’m making the game for). None of the controls work, and I’ve changed literally nothing since I tried it the previous time I had Unity open.
Then, if I mess with anything to do with controls, it resets everything and works fine.
So for example, it wasn’t letting any inputs work to control the ship. I have two scripts, one for movement, and one for shooting. I drag the shooting script on another object, and all of a sudden everything works, including the movement, which I’ve done nothing to. Then, if I delete the new shooting script, it still works. So I’m back to EXACTLY what the project was like before, and before it didn’t work, and now it does.

I’m scared for actually making builds of the game, because if it doesn’t work when testing it, there’s no guarantee it will work when I actually build it.
This really really feels like a bug in Unity. Is there a way around this? Are others experiencing it? What’s the protocol here?

EDIT: Just closed down Unity, started it back up, and the same thing happened. It’s a consistent issue, happened three times in a row now.

We can’t help you if we can’t see your code.

What are you using for input? I always use Rewired.

Generally speaking, stopping and restarting Unity does not break input systems. I have done extensive work with game controllers and Unity, and I have never run into a bug where restarting Unity broke the game controller support. When my code is right, then it works every time I open Unity and it works on every platform I build my games for.

Here’s the code in case that helps. I’m definitely new to all of this, so I actually don’t know what you mean by rewired controls.
There are two different scripts, first is moving the ship, second is shooting the laser. Both of them work perfectly, but then don’t work upon loading up Unity again, but will work again exactly as they are, if I just add and delete a script from an object.

void Update()
{
float verticalMove = Input.GetAxis(“Vertical”) * -10 * MoveSpeedVertical;
float horizontalMove = Input.GetAxis(“Horizontal”) * -10 * MoveSpeedHorizontal;
verticalMove *= Time.deltaTime;
horizontalMove *= Time.deltaTime;
ShipRigid.velocity = new Vector3(0, verticalMove, horizontalMove);
}

void Update()
{
Countdown -= 1;
if (Countdown <= 0)
{
if (Input.GetKey(keyShoot))
{
Countdown = Interval;
ShipPos = ShipObject.transform.position;
ShipPos.x += 2;
ShipPos.y -= 0.5f;
float verticalTilt = Input.GetAxis(“Vertical”) * -07;
float horizontalTilt = Input.GetAxis(“Horizontal”) * 14;
var laser = Instantiate(goCreate, ShipPos, Quaternion.Euler(0,horizontalTilt,verticalTilt));
}
}
}

Try making a simple script that displays axis value in a text field and updates it every frame. This will let you figure out if the input works.

The part where you say “I drag the shooting script on another object” makes me wonder if there’s some hidden initialization part that only gets executed when you attach the script somewhere, but is not serialized, and that’s why it stops working upon restart. Additionally check console for error messages.

1 Like

I had problems with XBox One controller on PC (so maybe it’s for XBox 360 too).
When you disconnect controller during play it sometimes mess with Input System (maybe it’s same problem on exit from Play Mode). When you connect it again Unity see controller but getting input keys stops working (you need to restart Unity or game to start working again).

I know of three solutions so far:

  • use new Unity Input System (I didn’t see this issue there)

  • use XInput (for example with XInputDotNet dll) for XBox controllers

  • use packages from Asset Store for managing input (Rewired, InControl etc)

Cool thanks! I’ll have to try that out. As I’ve been using it more, it doesn’t always do it, so there’s got to be something like what you said causing it. Thanks everyone for the help!