- Home /
TouchPhase.Began not detected.
In my input script I am using touchPhase types to execute specific functions. My only problem is that TouchPhase.Began is not detected at any time both on Unity Remote and when build on android device. Is it possible to detect the TouchPhase.Began at all?
if you could show us your script maybe we could help you more. There could be many things going on
function FixedInputs () { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Began) { //Do something } } }
I am guessing now that this might happen because of the FixedUpdate. Am I right?
What if I need to script input for movement of a rigidbody? Is there a better way rather then using FixedUpdate?
Answer by whydoidoit · Jun 20, 2013 at 01:14 AM
Don't use FixedUpdate for input. The problem with FixedUpdate is that it may run many times in a frame or not at all and there is no guarantee that events will be prepared properly when running it.
You need to get your input in a normal Update and then apply it to the rigidbody. If you are physically moving the body you want to set flags or some other method in your Update and then apply it on the next FixedUpdate. If you are adding forces you can do that anywhere. If it is kinematic then you can also move it anywhere.
Thanks for that, I didn't notice that I could Update since I am directly moving a Is$$anonymous$$inematic object which is jointed to the other rigidbody.
But I'm still having the same problem, this time with canceled. Inside Update i'm doing this:
if (Input.touchCount == 1) {
print(Input.GetTouch(0).phase);
}
Canceled is never printed. This is strange :S. I guess I have to create my own trigger for no touch.
And I'm sure it's not a problem with fps because I've built it on my android, printing the phase OnGUI and fps is over 50
Cancelled is an odd touch phase, are you sure you aren't looking for Ended?
I am just printing the Input.GetTouch(0).phase and it never prints neither Canceled nor Ended. And yes inside my original code, I am sure I was checking for Canceled. I also check for both - Cancelled || Ended. Even though I know that ended is fired when touches count are over the limit.
I am now doing this to check whether a touch is present or not:
if (Input.touchCount == 1) {
print(Input.GetTouch(0).phase);
}
else (Input.touchCount == 0)
print("Nothing");
I would like to hear about any other better solutions if any :)
If you iterate across the Input.touches collection do you find it? Rather than checking only when touchCount > 0?
Answer by OmarAlhaddad · Jun 19, 2013 at 10:28 PM
This have worked for me every single time, in C# but JS should be similar.
foreach (Touch evt in Input.touches)
{
if (evt.phase == TouchPhase.Began)
{
//...
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613104444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 2D Touch Controll via on screen button for Mobile 0 Answers
Get Touch touch phase began is grounded not working 2 Answers
Check for Ui clicks 0 Answers
Detect smartphone movement 0 Answers
When iOS framerate lags, are TouchPhase.Begans getting lost? 1 Answer