0

I'm working on implementing a click-and-drag or swipe style function in my Unity game. Recently it started ignoring my touch input, and after adding the following code to my GameController I found out why:

void Update () {
    Touch[] touches = Input.touches;
    Debug.Log (Input.touchCount);
    for (int i = 0; i < touches.Length; i++) {
        Touch touch = touches [i];
        Debug.Log (touch.phase.ToString ());
        Debug.Log ("Raw Position Touch(" + i + ")| X: " + touch.rawPosition.x.ToString() + " Y: " + touch.rawPosition.y.ToString());
    }
}

which produces the following output at this exact position every frame:

1
Stationary
Raw Position Touch(0)| X: 647.7088 Y: 92.50534

If I then touch the screen it will of course also show an appropriate Raw Position for my finger. Ex:

2
Stationary
Raw Position Touch(0)| X: 647.7088 Y: 92.5034
Began
Raw Position Touch(1)| X: 526.8154 Y: 307.6912

This scared the hell out me. I figured that I had probably broken my touchscreen. I'm programming on a Win 10 laptop with touchscreen capability, which is really nice for testing mobile apps, and I figured I'd probably busted it and I had a phantom touch stuck there forever. However to test that I went into the device manager and disabled the touchscreen and it's still showing the same touch every frame.

Is it possible that I'm somehow instantiating a touch event elsewhere in my code? if so what would that code look like?

  • Maybe the first one is the mouse. Try to move the mouse while this is running and see if `Raw Position Touch(0)` position changes – Programmer Apr 21 '18 at 07:53
  • @Programmer sadly not... just double checked. Until recently my code was handling touches with mouse button clicks and just letting android do the dirty work for me, but I've gotten to the point in development where I need to actually use the touch functions. clicking, moving the mouse etc has no effect unfortunately – Dr_StrangeKill Apr 21 '18 at 07:55
  • @Programmer do you know if it's possible to instantiate a touch event somehow? that seems to be the only way a touch would show up, and the fact that the touch doesn't move a centimeter tells me that there's something fishy going on. – Dr_StrangeKill Apr 21 '18 at 08:00
  • 2
    There is something wrong with your computer or just a bug with Unity. *"I'm programming on a Win 10 laptop with touchscreen capability, which is really nice for testing mobile apps"* This is wrong. You need a real mobile device like iOS or Android to test your mobile app otherwise expect more issues when you release your app. The reason is because the API Unity wrapped inside `Touch` does not work on every Windows computer. I've seen many questions about it not working at-all even with touch screen. You need a real mobile device that's not a Window device. – Programmer Apr 21 '18 at 08:08
  • @programmer I suppose I should clarify _"I'm programming on a Win 10 laptop with touchscreen capability, which has been really convenient for comparable touch functionality in the editor, to test small changes to the program before actually building to the LG Android I have connected to said laptop"_. It's been working fine so far. this bug just showed up. I just pushed another build to my phone and the functionality seems unimpaired completely, so you're probably right about a bug or glitch in unity. I'm about to restart Unity to see if it fixes it. – Dr_StrangeKill Apr 21 '18 at 08:17
  • I know. The problem is that Microsoft don't make the hardware or driver of these and the companies that do don't follow some rules resulting to issues. It's just like joystick issues where some joystick causes some issues on Windows when accessing them with the Windows API ehile others work. You test your mobile apps with Android or iOS. Don't consider laptop a mobile device for testing mobile apps with Unity even if it works. It can be used for development but not for replacement for testing on mobile devices. My question: Why don't you use iOS or Android device? A cheap one is fine – Programmer Apr 21 '18 at 08:24
  • I didn't even realize there were android devices that could run full versions of Unity. Can Chromebooks run Unity? The long answer to that is that I'm doing this in my spare time and using what I have. The short answer is I'm broke. All that being said, restarting Unity made the error disappear completely. I think I know what caused it too: I paused the program on a frame where i was touching the screen, probably edited code dealing with touches in some way, and got the computer/unity confused. That's my best guess. – Dr_StrangeKill Apr 21 '18 at 08:29
  • To clarify though, is it EVER possible to instantiate a touch event in code? – Dr_StrangeKill Apr 21 '18 at 08:31
  • 1
    No, because there is no Unity API for that. Possible only if you downloaded a plugin that is doing so with a native API. When I said "test on Android or iOS", I didn't mean running Unity Editor on those devices. I meant, you should build your project with Unity into executable then run your app on the physical device. That's what you should be doing. With **Unity Remote** you can [speed](https://stackoverflow.com/questions/39107153/how-to-speed-up-the-build-and-run-process-in-unity-for-mobile-devices-ios-androi) this up without building it at-all. – Programmer Apr 21 '18 at 08:38
  • @Programmer Thanks a lot, just double checking. Gives me peace of mind knowing that if a touch shows up it's either because I touched something, or because Windows isn't Android ;) If I've understood what you've said correctly then I'm doing this more or less right by developing on my laptop and testing on my phone. Unity Remote sounds like a really good recommendation for me as well. You've been a great help. – Dr_StrangeKill Apr 21 '18 at 08:45
  • You are doing right by developing with laptop. Now, you need a testing device. A $40 used android should be fine for touch screen test. Glad I was able to help. – Programmer Apr 21 '18 at 09:02

0 Answers0