I’m working on some UI for a game. It involves showing multiple entries with character portraits. The portraits are different sizes and already packed into a sprite sheet using Texture Packer.
I want to set the portrait for each entry using code. Best practices say to avoid using the Resources folder if possible. So then my options seem to be adding my sprite sheet to a SpriteAtlas or to create a public array in my code and drag the sprites into the array using the inspector. From what I can tell, a SpriteAtlas would re-pack the sprites with its own settings and the array would have to be updated each time I update the sprite sheet with more character art.
Are these my only options or perhaps I am simply unaware of an alternative method?
I’m more than willing to pivot to using the Resources folder where necessary, but I figured I should ask first to see if there are any alternatives. So far, lots of Googling has shown me there really isn’t.
There are, especially with asset bundles and addressables, both of which are extremely powerful.
Both of them also require a LOT of extra understanding and to write a little more boilerplate, and to be much more mindful of lifecycle and loading. But in return both of the above give you capabilities for late-built asset delivery that are unparalleled.
If you just need to load stuff already in the project, Resources.Load and Resources.LoadAll are falling-down dead simple and it has the side benefit that it actually works every single time you use it.
Call me weird, but I like that. That’s MY kinda “best practices.”
BTW, here’s my dynamic UI example, attached. It creates buttons according to the Resources that it can LoadAll from a folder, using a pre-made in-scene template “entry.”
Yeah, I’ve already made use of addressables where it was appropriate. In this case, though, turning the character art into addressables would be like using a jackhammer to put in a nail.
I’m curious because I only see that solution posted on internet, but Unity provide NO way of pulling a list of sprites, from a defined Texture without using Resources folder or AssetDatabase ?