Hello all,
I’m working on a mobile game, it relies on drawing shapes on screen.
I have a TouchManager script that checks if the user is drawing.
- The FIRST time the user draws, it turns out my code is super slow.
- the SECOND time and after, it’s smooth.
I first thought that I was doing different calculations between the first and the second time, but then I decided to add a stopwatch that checks raw execution time, and the results drive me nuts …
void Update()
{
// ========================= START OF DRAWING =========================
if (iSdrawing == false && Input.GetMouseButtonDown(0))
{
stopWatchTouchManager.Reset();
stopWatchTouchManager.Start();
stopWatchTouchManager.Stop();
UnityEngine.Debug.Log("Time elapsed :" + stopWatchTouchManager.ElapsedTicks);
//below the rest of the code
First time I run through this loop : 15 ~ 20 ticks
Second time and after : 1 ~ 2 ticks !!
I always wait a few seconds between app startup and first draw so that I make sure all initialization code has been done already.
And of course if I do the same exercice on all code that executes that if statement, I end up with ~ 15000 ticks the first time and then ~ 1500 ticks. So about a 10 times difference.
On PC it’s not really noticeable but when I test my game on a relatively low end mobile device, the game stutters for the first shape drawn which is very uncomfortable.
Any idea ?
Cheers !
Pierre