Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How to detect a minor freeze in game

Discussion in 'Scripting' started by xDayhawk, Apr 17, 2021.

  1. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    Hi all!

    I created a pretty simple mobile game and i've noticed some weird freeze while playing on Mobile.
    paying closer attention made me realize it also happens on my PC while on Play mode, but its much faster so i hardly notice it, its there though.

    my game is based on a basic char that picks up fuel charges to go up and up, i have around 20 levels.

    the issue is:
    when i pick up the first fuel charge, on the first level i choose, then i see a tiny 0.2s-0.3s freeze and then everything continues as normal...
    • it doesn't matter which first level i choose, it can be level 3 or 8, as long as its the first level of the current session
    • by current session i mean - only if i close the game entirely, and reopen it, then on the first level i choose i'll see it again
    • it only happens once on the first level i choose, if i restart the level, go to another level, nothing freezes.
    • I went over my code and i really doesn't create or start a lot of things.

    My questions is -
    How would you tackle a situation like this?
    What tools do u recommend (in Unity) that can help me investigate or drill down deeper?

    Thanks,
     
    Last edited: Apr 17, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,522
    The profiler (Window -> Analysis -> Profiler) is always a great place to start.

    For a single stutter like this, sometimes it is just assets getting loaded. One way to test that is to cover your play screen with a black "loading" screen, wait 1 second, then remove it.
     
  3. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    ok, i ended up just removing parts of the code and see what handles better, and it seems its all because of instantiating 1 prefab, which is a pretty lame empty object with an animator, and a child object which is a textMeshPro.
    the animator makes the textMesh popup and then disappears..
    its what i use for "floating text" in case of a pickup, dmg, etc'...

    i really can't understand why the first one is causing this freeze, is this something related to textMeshPro?
    i put a dummy instantiate at the Start before everything begins to move, and make the text empty so it would appear, that solved my issue (although i don't quite understand what it is yet).

    Thanks for your help @Kurt-Dekker , i took your advice on putting it on the loading screen (that's why i put it on Start).
     
    Kurt-Dekker likes this.