I’m wondering what I can do to have my game load certain graphics before the code directly calls for them.
I recently got my game running on my xbox via UWP. When the game starts up, I’ve got a classic reverse iris wipe on the title screen.
But when I run it on the xbox, the first time the game runs, it balks when that wipe starts, missing frames for a good quarter or even half a second, and the wipe never runs properly because of it.
I know this isn’t really a big thing, but I really like how the effect looks. And since it takes place at the literal beginning of the game, it makes an impression to player, and I really want to clean this up to run smoothly.
I’m looking over my code, and the other thing that ever happens at that point is when the game loads the graphic for the wipe. So my guess is that the game doesn’t actually have that in its memory, and it takes just a frame or two to unpack it or whatever, ruining the whole effect.
(BTW, the image is in the resources directory, and gets loaded when the wipe function starts.)
I also notice that when my character makes his first transformation the game pauses for just a couple frames as it loads the new sprites and animation controller for the player character.
Nowhere else have I noticed the game pausing for a few frames when it loads something, (though I may find more as my game grows,) and it only has the problem the first time it loads it.
I’m wondering if there is anything I can do to get the game to load all of these assets at a more convenient time, like during some scene transition or whatever.
If the model/effect you want to preload is something you use in nearly all your scenes, you can add the prefab to Preloaded Assets under Player options. These will always be loaded when the game loads. I think they probably always take up some memory even when they’re not being used due to this, but it means instantiating them is very fast.
For effects/models you don’t use in every scene, the other way is to add the object to some other object in your scene, and have it there at all times. When the scene first loads, you disable the object a frame later. This usually occurs during a scene transition, so a bit of stuttering there usually doesn’t matter. After a frame or two pass, you can disable the preloaded object. Subsequent instantiation of that object should be much smoother.
Hmm, it would probably be worth it to add some items to the preloaded assets; I will look into it.
And your second idea sounds pretty solid; moreoever it leads me to think I could just drop the texture in my scene somewhere off-camera. I’ll try that and see if it works out. Thanks!
Yup, I’ve done that before too. Just adding a bunch of objects with a bunch of textures, forces them to load, so there’s less load burden later. Usually just disable the game object afterwards as there’s no reason to sustain the (maybe minimal) resource cost of an unnecessarily active game object.
Honestly, it’s one sprite. Considering how I’ve got a few levels I made before tile maps were introduced to Unity and those have a good thousand or more sprites making up the level geometry… ¯_(ツ)_/¯
Dang it, I have the texture for the wipe sitting inside the level, but the game still balks when it first starts on my xbox. I have no idea what is causing this. The first thing the game does is it shows a custom splash screen and it waits for the player to hit a button before it does anything. So it sits on the title screen for several seconds or longer, not doing anything, but it still hangs for a good second when it tries to perform that wipe. I don’t know what could be causing this problem.
I draw an image on the HUD to simulate a splash screen. One wipe to transition from that image, but then when the second wipe un-wipes the screen it just pauses; it pauses so long I don’t see ANY of the wipe before it finishes.
I can exit eh app and start it again, and this time it just balks for a fraction of a second while performing the wipe.
What could even be causing this slow down?
This only happens in a build actually running on the XBox, not on a Windows build, and not when running in the editor? I’m not familiar with how to debug on an actual XBox, and whether you can attach the profiler to the build or not, the way you can with a Windows build. Maybe someone with some experience profiling XBox issues can give some recommendations.