Unity Accessing Prefab From Code in Compile Time

There would be multiple ways to do this but I would create a folder inside of a folder called “Resources”. Lets just say we call it “Weapons”. You can then load all of the files in that folder once when the scene loads and keep them in an array like this:

GameObject[] weapons = Resources.LoadAll<GameObject>("Weapons");

The advantage here is that you only load the assets once so you don’t have to load them during gameplay.

However, it shouldn’t actually be cumbersome to manually assign the assets in the editor since you can just shift click to select all of them and drag them into the array.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top