Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by m1le · Apr 03, 2018 at 09:54 AM · androidtouchlatency

Latency with android touch

Hello. Maybe someone ask for this but i don't find it.

Had a very simple code: Pass my finger on a ball to push it. So just a ball and the floor (not too many object!!!).

In the editor with Input.GetMouseButton it work well. But when i test it on android device, there's a very short latency when my finger pass on the ball, and when the force apply on it. So it works, but doesn't look great !

I tried many sort of detection, thought that is maybe the problem. Test with update, fixedUpdate, reduce timestep etc...

But at the end, i think that the problem of latency is the response of touch in android. Am i right ? And is there any solution ?

Thanks (Sorry i'm not english, so forgive my mistake)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Apr 03, 2018 at 02:26 PM 0
Share

Perhaps its time to post some code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Apr 03, 2018 at 12:03 PM

You'll see this is a common issue. You should implement Input.touches instead https://docs.unity3d.com/ScriptReference/Input-touches.html

~

Ive read about foreach having some issues (maybe performance related) compared to a for loop. It shouldnt cause this kind of issue. I would suspect you are running touches from FixedUpdate. Try Update instead.

If you use different methods in editor and device, use proper 'platform specific directives'.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image m1le · Apr 03, 2018 at 12:46 PM 0
Share

Thanks for your answer. But i made a mistake in my question. Sure i am using Input.touch when i run it on android. I try with foreach (Touch touch in Input.touches), think foreach go slower so try : if (Input.touchCount == 1) and if (Input.GetTouch(0).phase == TouchPhase.Began) etc... But the performance still remain the same.

avatar image m1le · Apr 03, 2018 at 12:56 PM 0
Share

Sorry, but in my question i wrote it, i try with both Update and FixedUpdate. Think i had to calculate the vector and it the ball in advance of when my finger is really on it, to handle this very short latency.

avatar image m1le · Apr 03, 2018 at 01:06 PM 0
Share

I don't understand "use proper 'platform specific directives'". I wrote the code on a computer wich not have touch. So for rapid test in the editor i use mouse, and touches when i test it in android. With #if UNITY_EDITOR. Is there a way to simulate touches in the computer ?

avatar image meat5000 ♦ m1le · Apr 03, 2018 at 02:24 PM 0
Share

You need to remember that when the editor is in Android mode it will execute Editor and Android behaviours. This can give debug issues. You may see that it works but in actual fact the Android part has failed and the editor part is the one thats giving the results, leaving you thinking the Android code is fine.

Ins$$anonymous$$d of

 #if UNITY_ANDROID 
 #endif
 #if UNITY_EDITOR
 #endif

Try something like

 #if UNITY_EDITOR && UNITY_ANDROID  //For code in Editor
 #endif
 
 #if !UNITY_EDITOR && UNITY_ANDROID   //For code on Device Only
 #endif

and see if there is a difference.

~

If you find you have to resort to precalculation, perhaps the issue lies within that code.

avatar image m1le · Apr 03, 2018 at 02:37 PM 0
Share

Had to go. I tried #if UNITY_EDITOR && UNITY_ANDROID... later to see if i have the same behaviour on the editor. Thanks for your time.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

191 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When The Screen Is Touched Jump 0 Answers

Android Touch Double Jump - Not working 0 Answers

Drag and Drop Touch Collision 1 Answer

Unity Input Touch 0 Answers

Android Controls 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges