- Home /
GameObject.Find vs Resources.Load
My game makes heavy use of the resources folder in unity for building up levels at run time. I have read that its bad practice to use the resources folder but I was wondering what the alternatives are?
Should I just add a single instance of each object into the scene then use GameObject.find instead? Then create instances from there.
At the moment I am using an object pool so I do only call the Resources.Load once per object
Is there any performance differences between Resources.Load and GameObject.Find?
Thanks Matt
@matt33315 - Just a comment - why not profile it? Does this already cause you a problem on your target platform? If not, to be honest, I wouldn't sweat too much too early, if game runs O$$anonymous$$ :)
Edit: also, by using resources load, you are loading during run time AFAI$$anonymous$$. But if you add all the GameObjects to scene, you'll be adding your data earlier than it's possibly needed and this could be possibly causing memory issues.
Then there are Asset Bundles - see this page: https://docs.unity3d.com/$$anonymous$$anual/LoadingResourcesatRuntime.html
Why don't you simply create prefabs in order to build your level at runtime and reference them in your LevelBuilder script?
Answer by tormentoarmagedoom · Sep 11, 2018 at 02:10 PM
Good day.
Use resources.load is not that bad, is much worst to use Gameobject.Find. If you need to asign a prfab variable, is always better to do not involve the scene for loading the asset. So GameObject.find is the worst solution.
The best solution, or at least the faster to execute, is assign the prefav to the variable via Unity inspector, but as we know is not the fastest for developing, so is better do it via script. At this point I think using resources.Load is the best option.
Bye!