- Home /
Resources loading vs public linking in inspector
Hello, i think the question is enough clear: what are the difference between load by script resources (http://docs.unity3d.com/Documentation/ScriptReference/Resources.html) and build a scene with elements already linked by inspector property? could it be see as encapsulation vs performance?
I think in most cases this is a matter of the loading time in the Webplayer or memory capacity.
Everything in the Resources floder is added to the build, whether it's used or not. If your assets etc. are not in the Rescources folder, only stuff you have linked in the inspector will be included in the build. I'll let someone who knows more give a more comprehensive answer.
Thanks both for answers. $$anonymous$$y main dubt is about performance, which one provides better performance? i add an example for next answer: Given a material, i can load it by script using resources locator loading or just write: public $$anonymous$$aterial my$$anonymous$$aterial; and then by inspector link it to the object that will use it and than save it in scene.
I'm curious for more optimization tips like this myself.
But for now I am assu$$anonymous$$g assigning them in the inspector is the way to go for performance since it seems like how they want you to use Unity.
The only downside to this is that the scenes will take up more memory than if you set up some kind of Level$$anonymous$$anagerScript that initializes all your prefabs to build the levels at run time.
But unless you're trying to keep your game really small like under 50$$anonymous$$B for mobile games for example, I think using the public inspector variables should be fine.
"Everything in the Resources floder is added to the build, whether it's used or not. If your assets etc. are not in the Rescources folder, only stuff you have linked in the inspector will be included in the build. I'll let someone who knows more give a more comprehensive answer."
I thought Unity dynamically deter$$anonymous$$ed what you actually use in the build so they wouldn't include unused assets in an .apk or .exe file for example?
Edit: looks like I missed the resources folder thing I think that is correct it will be auto included.
From: http://docs.unity3d.com/Documentation/ScriptReference/Resources.html
In Unity you usually don't use path names to access assets, ins$$anonymous$$d you expose a reference to an asset by declaring a member-variable, and then assign it in the inspector. When using this technique Unity can automatically calculate which assets are used when building a player.
Seems the answer "yes, use public and inspector linking".
But it goes against encapsulation principle of oop. However it's true that unity+c# is half scripting half oop.
If someone know more, please add a comment =)
Answer by dacaramo · Jun 19, 2020 at 09:02 PM
Like 7 years late but answering cause a while ago I had the same doubt, and also because i'm wishing to know if somebody thinks that Ressources loading via scripting is indeed useful rather than useless.
@valerik I dont think that loading ressources via scripting will have any advantage over letting unity doing it by it's self, according to the ressources and assets Unity tutorial, they even say that the best practice for the usage of the Ressources system is not using it. https://learn.unity.com/tutorial/assets-resources-and-assetbundles#5c7f8528edbc2a002053b5a7
The only potential use that I can think of is use it when loading a scene. Instead of creating a copy of a pre-existing GameObject by using GameObject.Instantiate() you can directly create the "pre-existing" GameObject from scratch by instantiating it using "new GameObject(String "name", Type[] listOfComponents)". When filling the components array you would need to load ressources from your assets. ... maybe useful when you have too many GameObjects that would need tons of copys and you dont want to have like hundreds of gameobjects just to make copies of them, instead you could directly create the GameObjects with their respective components and properties.
Indeed, in this last case , public linking will downgrade your performance, and will be better to use the Ressources system via scripting.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111841im_/https://answers.unity.com/themes/thub/images/avi.jpg)