- Home /
Serialized variable vs Resources.Load()
Hello community! I've seen many questions discussing the difference between Serialized private members and public ones. I couldn't find an answer to a similar but different problem though, hence my question:
I need to access a Material from within my script. As far as I know I can do one of two things:
Create a variable of type Material with [SerializeField] modifier and drag the desired item in the inspector to connect it.
Use Resources.Load() and assign it to a variable of type Material
My question is if there is any reason to use one over the other, performance-wise or other? I should add that the script will be tied to a prefab, which will be instantiated quite a few times, so the script will also get executed many times.
Best wishes and thank you in advance
Answer by Hellium · Mar 04, 2017 at 08:51 AM
2.1. Best Practices for the Resources System
Don't use it.
This strong recommendation is made for several reasons:
Use of the Resources folder makes fine-grained memory management more difficult.
Improper use of Resources folders will increase application startup time and the length of builds.
As the number of Resources folders increases, management of the Assets within those folders becomes very difficult.
The Resources system degrades a project's ability to deliver custom content to specific platforms and eliminates the possibility of incremental content upgrades.
AssetBundle Variants are Unity's primary tool for adjusting content on a per-device basis.
Source : https://unity3d.com/fr/learn/tutorials/topics/best-practices/resources-folder
Moreover :
If you change the name / location of the asset, you will have to find very references of this asset in your code and change the path, and, since the path is a simple string, it's very hard to track it all over you code.
The assets you put here may be accessible by the users after the build (at least, on a PC build)
The assets put in the Resources folder are directly put in the build, without compression or optimization from Unity, and are not removed even if you never use them in your code (Unity removes the unused assets in the non-Resource folders.)
Also, check this post : http://answers.unity3d.com/questions/319127/goods-and-bads-about-using-resourcesload.html
Your answer
Follow this Question
Related Questions
Fast, easy serialization library for Unity? 0 Answers
How to save/load references to components and prefabs 1 Answer
Unity Not Loading 0 Answers
Unity Serializer - saves delete after restarting game 2 Answers
SerializationException: Type UnityEngine.UI.Button is not marked as Serializable. Solution 1 Answer