Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Function called with latency at the first time

Discussion in 'Scripting' started by shuskry, May 23, 2024.

  1. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    474
    I'm currently making a game on Android, and I discovered a small bug that's probably already known but for which I can't find any solution.
    The problem does not appear on Windows or in the Unity editor but in Android mobile.

    I created a button on a Canvas, and it called a simple function allowing you to change a text "A" to "B".

    No complicated code, just a simple text.mynewtext changed in a public function assigned directly to the button via the editor.

    The problem is that if I click on this button for the first time after launching the application on mobile, whatever the waiting time between the moment when the application is launched and when I press the button. There is a small latency between touch and text change of 0.2-0.3s.

    I then created a reset after 5 seconds to test, and if I press the button again once the reset has passed, then the text changes instantly.

    I don't know where it could come from, if it's on the script side, or if it's a problem with the detection of the first press of the button?

    If anyone can explain to me where this comes from and how I can get around this problem I would be very grateful!

    Ps: I didn't show any code or screenshot because I don't use any particular method or way of doing things, just 1 line of code, a Textmesh pro, and a button

    Have a nice day!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,391
    You need to use the profiler to see where the overhead is. It's hard for us to say what it could be.
     
    Last edited: May 24, 2024
    shuskry, lordofduct and Ryiah like this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,683
    Is it set to anything in its initial state? Because that sounds like an asset like the font is having to be loaded for the first time.
     
    shuskry and lordofduct like this.
  4. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    474
    Hello @spiney199 ,
    I tried in a blank URP project , with no asset added ( exept TextMeshPro).. Even if i'm using the profiler I'm not sur to find something that I can solve by myself .. I'm not competent enough I think to solve an existing problem...But i'll will do that tonight , just in case ^^
    Thanks for help me ! I will post the result after analysis


    Hi ! @Ryiah
    Yes, the text is already set to "A".
    But at the origin of my tests, the button was used to trigger an animation, and when I discovered this latency problem, I minimized the experience with a text to understand but I was no further ahead..
    Thanks for trying to help me !