I am trying to track down a bug where when my game first starts, it freezes momentarily as it performs a screen wipe, ruining the wipe effect (which is timed with the music, so it is really noticeable.) I do not see this happen when I test it within the editor, but it does happen when I run the game on my xbox.
I thought the problem might be that the game was freezing for just a moment because it is loading the texture I am drawing on the screen to produce the wipe. I dropped a copy of this texture into my scene just to make sure the system pre-loads it, but it still has this problem. So maybe it still takes half a second to actually load it into the right part of its memory or something. So I thought: why not add some code to the wipe effect so that it just waits one frame after it loads the texture, that way if it is taking just an extra moment to load the texture, it won’t actually start the wipe until the next time update is called. Thus if it takes a moment to load the texture, the wipe will start after this happens.
But when I went through my code, I found that I was already doing this.
The process works like this: I have code that gets called somewhere within the update function, which looks something like this:
SetWipeType(WipeType.IrisCircle);
StartWipeIn();
SetWipeType will tell the script to load the requisite textures and set a few other variables. StartWipeIn actually looks like this:
public void StartWipeIn() {
StartCoroutine(StartWipeInNextFrame());
}
IEnumerator StartWipeInNextFrame() {
yield return null;
if (CurrentWipe != WipeType.MapWipe)
bScreenWipeActive = true;
bScreenWipedOut = false;
wipeTimer = 0;
bWipingIn = true;
GM.PlayMusic();
}
So I’m wondering if using that IEnumerator with the yield return isn’t going to actually execute on the next rendered frame. It seems to do this in the Editor, and I don’t recall having this problem on Android when I was using that platform many years ago. But maybe UWP doesn’t handle frames in quite the same way?
Is it possible that this code above actually won’t execute on the next rendered frame, thus it tries to execute while the game is still lagging behind for a moment as it loads data?
I’m just spit-balling here; I can’t figure out why this would happen.
The game opens on a scene for the title screen, and initially has a splash screen drawn by the HUD to cover the screen. When the player presses a button I start a wipe. When the wipe finishes that splash screen stops being drawn and the wipe-in process automatically starts, using the code above. But the game stutters a bit on this wipe-in. It doesn’t usually have problems when the game has been running a while, just for that first run when the game first turns on. Hell, even if I return to home and re-launch the game, it only has the slightest of stuttering. But if I turn on the console and launch the game (or upload a new build and launch the game) it will balk on that wipe-in, usually with my screen remaining completely black (from the wipe-out having just finished) while I hear the music playing, and then the screen suddenly appears because it balked for nearly the full second the wipe lasts.