Load object into Hierarchy?

Hi guys,

Question… How do i load an asset thats in my resources folder and place it into a hierarchy? For instance, Main Camera > Object2 > theLoadedObject

I have this so far but it only loads it into the root level:

GameObject prefab4 = Resources.Load ("theLoadedObject") as GameObject;

I take it you are asking how you would set the parent of an instantiated GameObject. In which case, you will need to use Transform.SetParent() to assign the prefab as a child of an existing object in the scene hierarchy. Here is the documentation link for it: Unity - Scripting API: Transform.SetParent

Based on the information you have provided, the following should accomplish what you are looking for:

EDIT 19-Oct-15

    // Use this for initialization
    private void Start()
    {
        GameObject theObject = Resources.Load("theLoadedObject") as GameObject;
        GameObject instance1 = Instantiate(theObject);

        Transform newParent = GameObject.FindWithTag("Player").GetComponent<Transform>();
        instance1.transform.SetParent(newParent, false);
    }

OMG You guys are legends! That seriously was doin my noggin in!!

Really appreciate your help guys! It means so much to have people like yourselves helping out, I’m not the best at coding and now that i can see how its done, i can learn it and apply it to other things.

OH GOSH THANK YOU!! :smiley: