r/Unity3D • u/Vladyslav_ko • 1d ago
Question Preloading room variations without keeping every background in memory
We're working on a Unity visual novel where returning to the same room later in the day gives you a different lighting variant. We want the transition to look like walking back into a familiar place, so a blank frame or a long pause between pictures is easy to notice.
The two approaches we're considering are keeping the current and next variants ready, or loading the next one as the player gets close to a time change. The second one sounds lighter until players pause, return to a menu, or skip straight to another scene.
For a small 2D project with large background textures, what would you measure first on a modest machine? I’m especially interested in how you decide whether a transition is worth preloading.
3
u/veerdonk 1d ago
Did you measure how long the pause actually is? My go to strategy is to implement something and optimize it afterwards if it is needed. It's really easy to get bogged down by unnecessary early optimization
1
u/Genebrisss 1d ago
If it's a small 2D project, can't you just dump everything there is into memory at game startup?
Also use new Direct Storage function they added.
1
u/keymonlab 1d ago
Since it's a VN, your script usually knows the next time change before the player gets there, so I'd start the Addressables load when that line is queued rather than by proximity. For pause, menu or skip, keep the last frame up and crossfade once the handle completes, so a late load reads as a slow fade instead of a blank frame. If the variants differ mostly in lighting, one base image plus a lighting overlay blended in a shader may save more memory than any preload scheme.
1
u/ledniv 11h ago
I would look at this as a memory management problem. Start by determining how much memory you can dedicate to backgrounds on your minimum target device. Remember that the size of the image on disk is not necessarily the amount of memory the texture occupies at runtime.
Since this is a visual novel, you already have a lot of information about which assets the player might need next. I would use that data to explicitly control when textures are loaded and released. You can define which backgrounds are required for each section of the story and which are shared across sections. That also makes it easier to determine which assets can safely be released when the player skips ahead.
I would also be careful with asynchronous loading. Just because something loads asynchronously does not mean it cannot cause a frame spike. Texture uploads and asset initialization can still affect performance. Profile the transition itself on your minimum target device.
Small plug: I cover memory management and the advantages and disadvantages of Unity's different asset loading solutions, including Resources, AssetBundles, and Addressables, in High Performance Unity Game Development with Data Oriented Design.
https://www.manning.com/books/high-performance-unity-game-development
1
u/JapanModelAsset 2h ago
One thing that might make this decision a lot easier: check whether the lighting variants actually need to be full separate backgrounds. In a lot of VNs the morning/evening/night versions of a room are the same painting with a colour grade and a few light shapes on top. If yours are close to that, you can keep a single base texture plus a small overlay or LUT per time of day, and the "transition" becomes a shader lerp, which costs nothing to preload.
If they really are separate paintings, before anything else I'd check texture compression and size. Big backgrounds left uncompressed or at 4K when the game runs at 1080p are usually what makes preloading feel expensive. With crunch/ASTC or BC7 at the right resolution, keeping current + next in memory is usually tiny for a 2D project, and you can stop worrying about the pause/menu/skip edge cases.
1
u/Holiday-Club3839 1d ago
I'd measure the transition hitch first, not the memory. On a modest machine the thing players notice is the frame spike when a new texture has to be decoded and uploaded, so record the Profiler timeline across the exact moment of the change and look at texture upload time against your frame budget.
Then check peak texture memory with only the current and next variant resident. If that peak is comfortably under your target, preloading is cheap insurance. If it isn't, make the transition itself carry the wait - a short door-opening animation or a fade gives the load somewhere to happen without reading as a stall.
The edge cases you mentioned are the real reason to cap it at two: pausing, returning to a menu, and jumping scenes all invalidate a speculative preload, so treat it as a one-step lookahead, never a queue. I ran into the same tradeoff building a 29-level puzzle where each level had its own asset set - keeping the whole pipeline warm cost more than the occasional load frame, but capping it at the next level only was the sweet spot.
If you do preload, Addressables with a fixed handle you release on scene exit keeps the variant from lingering.