Is it possible to get a prefab object from its asset path?

For instance, I want to be able to instantiate a gameObject from a prefab stored in “Assets/Prefab/Items/Key_yellow.prefab”.
Thank you.

Loading Resources at Runtime is what you are looking for.

For everybody new: The answers above weren’t working for me with the Unity versions from 2019 and on.

Yes, you might want to check the Docs at Unity - Manual: Loading Resources at Runtime

Here it says

you simply create a new folder inside
the Project View , and name the folder
“Resources”. You can have multiple
Resource Folders organized differently
in your Project. Whenever you want to
load an asset from one of these
folders, you call Resources.Load()

  • So, you have to move your files e.g. to Assets/Resources/ - let us assume your prefab is called Cube.prefab it is now at Assets/Resources/Cube.prefab.
  • To load it programmatically, you now can call Resources.Load("Cube"); (Note: You neither need the Resources prefix, nor the .prefab ending)
  • Instantiation is the same as above: GameObject.Instantiate((UnityEngine.Object) Resources.Load("Cube"), Vector3.zero, Quaternion.identity);

Long story short:

 private UnityEngine.Object LoadPrefabFromFile(string filename)
 {
     Debug.Log("Trying to load LevelPrefab from file ("+filename+ ")...");
     var loadedObject = Resources.Load("Levels/" + filename);
     if (loadedObject == null)
     {
         throw new FileNotFoundException("...no file found - please check the configuration");
     }
     return loadedObject;
}
    
 // Called via:
 var loadedPrefabResource = LoadPrefabFromFile("Cube");
 Instantiate(loadedPrefabResource, Vector3.zero, Quaternion.identity);

@tmdchi you may want to have a look

UnityEngine.Object pPrefab = Resources.Load(“Assets/Prefab/Items/Key_yellow”); // note: not .prefab!
GameObject pNewObject = (GameObject)GameObject.Instantiate(pPrefab, Vector3.zero, Quaternion.identity);

You don’t have to use the ressource folder as long as you want to use this only in the editor, not at runtime.

Here is a little script that finds you all prefabs in a specific folder:

private void GetAllPrefabs()
    {
        string[] foldersToSearch = {"Assets"};
        List<GameObject> allPrefabs = GetAssets<GameObject>(foldersToSearch, "t:prefab");
    }
    
public static List<T> GetAssets<T>(string[] _foldersToSearch, string _filter) where T : UnityEngine.Object
    {
        string[] guids = AssetDatabase.FindAssets(_filter, _foldersToSearch);
        List<T> a = new List<T>();
        for (int i = 0; i < guids.Length; i++)
        {
            string path = AssetDatabase.GUIDToAssetPath(guids*);*

a.Add(AssetDatabase.LoadAssetAtPath(path));
}
return a;
}

This is what worked for me (unity 2017.3)

UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/PlayerController.prefab", typeof(PlayerController)); 
PlayerController player = Instantiate(prefab) as PlayerController;

May be yes it is possible. You should certainly refer to this interesting read on Reddit Downloader. Maybe it might help you.