#Load file at runtime

1 messages · Page 1 of 1 (latest)

hallow isle
#

I'm working on a dialogue system for my game and need a way to load images at runtime. I don't want to use Resources since I might have up to hundreds of images for different characters, poses, expressions etc. Additionally, manually having to drag and drop the images for each characters hundreds of times sounds horribly tedious when I could instead use a file hierarchy system.

#

Additionally, I'm having all of the text and logic as to what character is talking and which expression/pose should be used in text files so that I can easily add more dialogue and localize the game later on.

#

If there's a better way to load and reference hundreds of files, do let me know

#

I had looked into a workaround using only C# but I'm really not sure how this will work with the game being built.

frozen bloom
# hallow isle I'm working on a dialogue system for my game and need a way to load images at ru...

I don't want to use Resources since I might have up to hundreds of images for different characters, poses, expressions etc.
I don't see why it would be a problem. Files from Resource folders are automatically added to the build, but they aren't automatically loaded into memory. Keep in mind that you can have multiple Resource folders.

If you want to reduce the build size, then Addressables package can handle it, as it can be used to download the game's content at runtime.

hallow isle
frozen bloom
# hallow isle I see! I must've been misinformed then since I've seen people say using Resource...

Probably a misunderstanding. Normally, Unity checks out which files are referenced anywhere (recursively, starting from included scenes), and then only the used assets are added to the build. The main issue with Resources is that Unity will always include them in build files, even if they're not used anywhere. In other words, Resources folder may increase your build size if you have a mess in your project.

To load the assets into your memory, you use Resources.Load, Resources.LoadAsync, or Resources.LoadAll. You might want to use Resources.UnloadUnusedAssets from time to time to unload assets you're no longer using. You can also unload these assets manually.

What I don't like about Resources is that you need to use file paths, which makes you likely to make a typo. However, if you want to load files based on some hierarchy naming, then using file paths actually benefits you.