finding instantiated prefabs

I have an object that has been instantiated like this:

Instantiate(Resources.Load("MyPrefab"));

Visually I can see that that is happening when I test the program. In another script, after this has been done, I’m trying to reference that instance, but this code returns null:

boss = GameObject.Find("MyPrefab");

Why? Shouldn’t that return the first one currently in the scene? I guess GameObject.Find() doesn’t find Instantiated objects? I looked for a “name” field in the prefab in case that was the source of the issue, but I’m not seeing one.

This may be a little late and I know this was already answered, but you can very easily refer to your instantiated prefab by creating a variable and making it equal to the instantiate’s return value:

GameObject myGameObject = Instantiate(Resources.Load("MyPrefab", typof(GameObject))) as GameObject;

myGameObject.name = "SomePrefabName";

You can then send it to your other script via a public variable or store it here with something vague…like

GameObject.Find("SomeOtherObject").GetComponent<SomeOtherScriptOnThatObject>().myOtherScriptGameObjectVar = myGameObject;

Bearing in mind of course that Find() and GetComponent() should be used as much as possible outside of frame loops.

Could it be that it’s not the real name of the instance? Just trying to figure out if that’s a possibility.

I would try renaming the GameObject you just instantiated to something else, then looking for that name.

Oh, another thing…are you sure your code which is looking for the GameObject is happening after the object has been Instantiated? I would use a debug statement to very the order.

If you are instantiating and looking in different Start/Awake methods it could be that the wrong Start/Awake is happening first.