So I have a lot of game assets in my resources folder. I didn’t learn until late last year that I’m really only supposed to use that for prototyping. So now I need to start moving assets out of there and call them in through other means.
I’m wondering what options I have for this. I only really know of two. I suspect there are other options I had not considered.
I’ll mention that I was using the resources folder just as a means to call/load/instantiate various assets through scripts. Anything I ever want to spawn in my scene, well, I need to be able to reference it through a script, now don’t I?
The first method, the one taught in most tutorials I come across, is to have a public/serialized variable within a script, and within the editor I just drop a reference to the asset inside the inspector. Then when my script needs to load an asset into the scene it just calls the one stored.
This is useful for anything that only ever needs one kind of thing. Like if an enemy shoots fireballs, and they only ever shoot one kind of fireball, this is the method of choice.
But it begins to be an issue when I have several things that need to be called, or when these things change. I don’t need most of these loaded into memory to be called at any moment, and there really isn’t any way to “unload” anything that I don’t need, nor only load an asset “if” it is needed. Anything that is referenced within an asset in my scene will be loaded when the scene loads; anything that asset references will be loaded, and so on recursively.
This is really only a good method for things that either A) could be needed at any point within a scene, or B) could be needed at any point within the entire game.
The second method is to use the Addressable Asset System. This is new to me, and I’m still reading about how to use it. I don’t fully understand its advantages and disadvantages, when it should and should not be used, etc. It mostly looks like a good replacement for using the resources folder, but I can easily suppose that there are circumstances where I might want to try something else.
(If anyone has any thoughts on the best ways to use this, I welcome them.)
What other methods are there that I can use to call an asset via script?
