- Home /
How do I instantiate a prefab from my asset files without using a public reference.
I need to instantiate a prefab but I can't simply use a public reference because the the actual prefab being used may change depending on events in the game.
I've looked for help and seen people recommending Resources.load, however after researching that I found that Resources.load should almost never be used.
I also found a suggestion to use AssetDatabase.LoadAssetAtPath, but that's a function of UnityEditor and therefore wouldn't work on builds, only in the editor.
Does anyone here know what we are supposed to use in place of those two things?
I don't understand why you can't use public references.
People do what you're talking about all the time - a lot of our prefabs, for example, have skinned or localised versions, so which one is needed is often dependent on things that have happened at runtime (even if it's just the choice of a locale).
That doesn't mean that public references don't work - it just means you need more of them, and a mechanism for picking the right one.
If that doesn't seem to fit your situation, then I think you should provide more detail of your situation, it's a bit vague at the moment.
Answer by AconitumNapellum · Dec 04, 2019 at 10:59 AM
Why you should never use Resources.Load? It's strange news to me.
EDIT: Just to give you an answer i guess you could check out Addressable Asset System, even if you could just use Resources.Load.
https://unity3d.com/learn/tutorials/topics/best-practices/resources-folder scroll down to 3.1, It's apparently been deprecated but kept for use in a few specific scenarios.
Thank you for you suggestion it seems like what I was looking for.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215657im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to use custom file types as Unity assets 1 Answer
Prefab in my asset bundle for iOS gets corrupted and doesn't show in the app 0 Answers
how do i link menu options to a button? 0 Answers
Get path to prefab asset not from instance is not working :/ 0 Answers
Prefab isn't centered on my cursor 0 Answers