Possible to get a prefab reference at runtime?

Given that I have a gameobject, can I get a reference to the prefab that I used to Instantiate it?

Currently, I create a variable in the newly Instantiated gameobject to store its prefab. I’m hoping Unity does this already and I can use that and clean up my code a bit.

Public GameObject MyPrefab; // reference to the prefab. Drag your prefab onto this in the inspector

private GameObject myPrefabInstance;

void Example()
{
myPrefabInstance = Instantiate(MyPrefab); // Instances the prefab and stores a reference to the instance in myPrefabInstance

Destroy(myPrefabInstance); // Destroys the instance of the prefab
}

Not sure if thats the kind of thing you were looking for!

Yeah, that’s the type of thing I have going, but I was just wondering if there was some native Unity functionality that I was overlooking. I guess not. Thanks tho.

I think another way is to have your prefabs in a “Resources” folder and look them up that way. From what I read its more expensive although I havent really looked into it.