Function called with latency at the first time

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!

You need to use the profiler to see where the overhead is. It’s hard for us to say what it could be.

3 Likes

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.

2 Likes

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 !