- Home /
About to gut my use of the Resources folder. What are the best practices going forward?
I have been using the Resources folder a lot. I have recently been informed that this is considered a very bad and dangerous thing to use for bigger projects. I dug in a little and found some evidence supporting this opinion: https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder
Current approach:
An enemy spawner triggers a new enemy spawn. The spawner calls Resources.Load() on the appropriate enemy prefab, initializes it, and kicks it off into the world.
Best-practice approach(?):
An enemy spawner has a reference to all enemy type prefabs as public variables on the script. When an enemy spawn is triggered, the spawner just initializes the prefab that is a public variable on it.
Am I understanding this properly? Is there any documentation that goes over the best practices here when looking for alternatives to the Resources folder?
What were some of the complaints you heard about Resources that worried you?
Here is documentation from them on it: https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder
Answer by TanselAltinel · Apr 26, 2018 at 03:03 PM
First and foremost, if you are instantiating a lot of game objects from prefabs, use pools.
By using pools, you'll have no need for Resources folder.
Here's a great starting point: https://unity3d.com/learn/tutorials/topics/scripting/object-pooling
I'm using PoolManager from path-o-logical games and after I instantiate my prefab, I can change anything on it by accessing components and scripts. Though any pooling system will work similarly, so you don't have to purchase an asset for it.
I don't think this is related to the question. Object pooling and managing how assets are organized within your build / deployment aren't really the same thing. OP doesn't seem to be using pools given how the question was phrased, but those issues aren't related to the concerns raised in their linked article.
OP is using Resources folder to load prefabs. This is the number on NO DO in Unity game development.
I've provided a useful answer to OP as how he is managing his game. He didn't ask a general question about Resources folder. He asked what would be a best practice to ditch usage of Resource folder and go on with development, without changing whole game structure.
So, it is not only related to question, it is also a better suitable answer to question ins$$anonymous$$d of advocating Resources folder usage.
But you didn't tell OP where you are keeping your prefabs. You can pool anything, regardless of where it's sitting (resources, inactive in hierarchy, assetbundle). The example tutorial you linked uses an object sitting in the hierarchy, would you recommend that to OP for their problem?