So I am going over Resources and how I can utilize this but am unsure. For, what I am doing, I thought this might be a good idea. I may develope a pause system with potentially two scrolling lists. Each list could contain a dozen plus items. I am building for mobile, so, if each time, I press pause, my user has the ability to open up one of these lists, would something like Resources be wise to utlize? Or just object.active = false suffice.
I would say yes and no… it may be beneficial of those objects cause your scene to initially load slowly, if they have little effect on the load time then it wouldn’t matter as much
resources are great when you want to better manage loading and unloading assets, perhaps ur scene crashes on load because of insufficient memory, with resources u can unload some unused assets to make room for the others
also, if u have many textures your swapping through with a next bottom for example, u can load an array of resources from a single folder without having to assign the textures in the inspector
So is resources just in regars to textures?
no you can load almost if not all types of assets from resources, but the same concept kinda applies, if you want to load a whole level mesh or prefab that you dot not want to be loaded from the initial load time you can call it from resources
basically, unity takes all assets required to run your scene and loads them at the start of the scene when it first loads. this includes assets that are not visible and even assets that are not being used yet but may become active from a script.
anything thats loaded from resources will not be loaded during the start of the scene, so you can tell unity when to load these assets in the middle of runtime, the only thing is you may experience a little to a lot of lag depending on the asset your loading during runtime
How is this any different than Instantiate? And, in theory, could I make a prefab of a section of a level, enemies, walls, bkg elements, and load them as as one element? Also, how does positioning work? Does Unity just place any object at VectorZero?
no you would likely have to define the resource before Instantiate,
just using resource.load(“my object”) will not place an object anywhere, it would be along the lines of
(untested code)
function Start(){
var myObject : GameObject = Resources.Load("myObject");
Instantiate(myObject, Vector3(20,20,20). Quaternion(0,0,0,0))
}
now if you were instancing a prefab, it would use the position/rotation of the prefab predefined in the inspector unless you specify like above
Sorry, I do not understand your post.
sorry i hit submit before i was finished lol, read again above
Ok, so does instantiate, only differ in that I can alter the position and rotation as part of the function? Is there any difference in cost to memory? Memory spike?
well like i said before its the difference of that asset your instancing being loading from the start of the scene or at runtime
if you drag the asset from your asset list and define it in the inspector then it will be loaded from the start, this will cause longer load time,
if you do NOT define the prefab in the inspector and only load it via script with resources it will not load from the start,
if your scene is crashing on loading due to running out of memory then you may want to load some things at runtime when you need them, then unload them when you don’t need them anymore
if you don’t use resources and you have the prefab loaded from start, it may take less memory and time during runtime to instance the prefab, but in return your initial load time of your scene will be longer
overall unless you are having a very long load time, crashing on load, or have a list of assets you want in an array without defining them in the inspector or as separate variables, there isn’t much of a need to use resources
for example say you have a brochure / book in your game or app with 50 pages to flip through, it may be better to use resources to flip through the pages because your device may crash trying to load 50 large full screen textures at once, resources will allow you to only load 1 at a time
I fully get it. I am just trying to see the the difference between Resources.Load(object) and Instantiate(object)