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 /
avatar image
0
Question by Maxik2k · Aug 08, 2019 at 01:29 AM · editorscenemobileeventsystem

EventSystem micro lag on the first touch

Hey! I have been writing a project and at one moment there was a problem. So I build my game for mobile devices. If I touch the screen there is micro lag and after it game works perfect. This lag takes milliseconds, but is's really annoying. I had spent lots of time to understand the reason of this proublem. So I created a new simple project with three objects on my scene: player, floor and camera. Then I tried to move the player using two simple scripts:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Movement : MonoBehaviour
 {
     private Rigidbody2D RB;
 
     public float speed;
 
     void Start()
     {
         RB = GetComponent<Rigidbody2D>();
     }
 
     void Update()
     {
         DetectInput();
     }
 
     public void MoveLeft()
     {
         RB.velocity = new Vector2(-speed, RB.velocity.y);
     }
 
     public void MoveRight()
     {
         RB.velocity = new Vector2(speed, RB.velocity.y);
     }
 
     public void StopMoving()
     {
         RB.velocity = new Vector2(0f, RB.velocity.y);
     }
 
     void DetectInput()
     {
         float x = Input.GetAxisRaw("Horizontal");
 
         if (x > 0)
             {
                 MoveRight();
             }
             else if (x < 0)
             {
                 MoveLeft();
             }
             else
             {
                 StopMoving();
             }
     }
 }

and:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Touch : MonoBehaviour
 {
     private Movement movement;
 
     // Start is called before the first frame update
     void Start()
     {
         movement = GetComponent<Movement>();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.touchCount > 0)
         {
             UnityEngine.Touch touch = Input.GetTouch(0);
             Vector3 touch_Pos = Camera.main.ScreenToWorldPoint(touch.position);
 
             if (touch_Pos.x > 0 && touch_Pos.y < 0)
             {
                 movement.MoveRight();
             }
             else if (touch_Pos.x < 0 && touch_Pos.y < 0)
             {
                 movement.MoveLeft();
             }
             else
             {
                 movement.StopMoving();
             }
         }
     }
 }
 

This is only one of many ways which I used to moving player. I also tried OnPointerDown, OnMouseDown and some other ways which I don't remember and got the same problem. I came to conclusion that the reason is different.

So, the scripts above worked perfect when I built the game for mobile. Player moved smooth as I want. But then I decided to add the fourth object on the scene - EventSystem! I didn't need to add it, but it was just an experiment. And I got the reason of my headache! EventSystem add the micro lag on the first touch on mobile. I have no idea how to fix this. Help me please!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

204 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 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

Graphics Emulation - OpenGL 3 1 Answer

Unity 5 editor set play width and height in pixels 1 Answer

Object Painter Editor Help 1 Answer

How to make Textured Wire mode non-transparent 0 Answers

What is the problem with the 2020.1.8 android module? 0 Answers


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