Hello,
I saw a post here a while ago talking about how it's not a good idea to leave tons of images in Unity's Resources folder when using the Visual Novel Framework's BackgroundManager system.
In my game I use dozens of images to compose the dialogues, just for the opening scene, for example, I have almost fifty images.
It worked great so far, but from what I understand this could become a problem in the future, as Unity loads all images from the Resources folder when starting the game (as per the post I found earlier).
Could someone explain this problem to me a little better and how can I avoid it?
Can I continue to put all my images in the Resources folder?
Using BackgroundManager with many images
Re: Using BackgroundManager with many images
Hi,
Pro: The Resources folder is easiest.
Con: All files in your Resources folder(s) are loaded into memory when the game starts. This increases your game's memory consumption and also takes longer to start the game.
One alternative is to reference images in individual scenes. For example, say you have 100 images, and the first 10 images are only used in the intro scene. Instead of using Resources, add those 10 images to Image or SpriteRenderer components in the intro scene, and use SetActive() sequencer commands to activate or deactivate them as needed. All 10 images will be loaded into memory while the intro scene is open, but they'll be released from memory when you leave the intro scene.
Another alternative is to use Addressables. This is a little more complicated, but the Dialogue System does provide helper methods (DialogueManager.LoadAsset and UnloadSset) to make it a little easier. If you're using the free VN starter framework package, its BackgroundManager uses DialogueManager.LoadAsset already. There's a recent thread where someone set up their VN project to use Addressables this way.
Pro: The Resources folder is easiest.
Con: All files in your Resources folder(s) are loaded into memory when the game starts. This increases your game's memory consumption and also takes longer to start the game.
One alternative is to reference images in individual scenes. For example, say you have 100 images, and the first 10 images are only used in the intro scene. Instead of using Resources, add those 10 images to Image or SpriteRenderer components in the intro scene, and use SetActive() sequencer commands to activate or deactivate them as needed. All 10 images will be loaded into memory while the intro scene is open, but they'll be released from memory when you leave the intro scene.
Another alternative is to use Addressables. This is a little more complicated, but the Dialogue System does provide helper methods (DialogueManager.LoadAsset and UnloadSset) to make it a little easier. If you're using the free VN starter framework package, its BackgroundManager uses DialogueManager.LoadAsset already. There's a recent thread where someone set up their VN project to use Addressables this way.