Referencing from assets in build

I’ve been trying to figure out how to reference game object’s in the assets folder for a few days now.

var MedBag = AssetDatabase.LoadAssetAtPath("Assets/Sprites/Items/MedBag.prefab",GameObject);
var AmmoBox = AssetDatabase.LoadAssetAtPath("Assets/Sprites/Items/AmmoBox.prefab",GameObject);

I’ve tried using this code and it works in the editor, but once I make a build it throws an error. So if someone could help me out with this it’d appreciated it :slight_smile:

AssetDatabase uses the unityeditor namespace which cannot be used at runtime.

What you are looking for is the Resources.Load. You will need to have a folder called Resources
This should explain it

1 Like

Thank you so much! :smile:

1 Like