I really don’t like that you have to place prefabs in resources folder to instantiate from scripts. It makes the project folder structure a mess and lots of scrolling and searching for certain prefabs.
I want to place prefabs in where I want to. Is there any easy workaround to achive this? Something that might work might be to make an empty scene and place prefabs and store their references to some static class’s variables so later you can get the prefab from the static class. But it sounds awkward. Can anyone give me a better idea?
If you keep your assets folder well organized with subfolders it shouldn’t be a problem to have all your resources there including the prefabs. I’m not sure you are doing it right but I think the cleanest way to instantiate prefabs is as follows:
- in the script from where the prefabs will be instantiated place a public variable of a type that can points to the prefab (a component included in the prefab, usually a Rigidbody, an AudioClip, etc)
- then in the inspector panel you should see this as a property of the object which has this script attached: drag your prefab from the well organized project panel to this slot, it should match if the prefab contains a component of the type set when declaring the public variable in the script
- and that’s all, then in the script code you can instantiate this kind of prefabs without having to have them scattered around (remember that you need to make a cast within the instantiation if you’re in C#)
hope it helps