Instantiating a new gameObject as a child of a different gameObject

here is the code
public void FillNextOpenSpot()

	GameObject newSelected = Instantiate (selected, openSpotPos, Quaternion.identity) as GameObject;
	newSelected.transform.SetParent (nextOpenSpot.transform); // tried this patent
	newSelected.transform.parent = nextOpenSpot.transform; // and tried this one too

nextOpenSpot is a game object that I have declared globally. The object is Instantiating but it’s just going straight to the top of the hierarchy. One weird thing that I found in troubleshooting is that it will child to the object the code is attached to if I changed the right side of the assignment of either patent to just “Transform”. It only doesn’t work when I try to specify a different transform.

Just to see if it changes anything, you could try

newSelected.transform.SetParent (nextOpenSpot.GetComponent<Transform>());

It is transform.parent, I don’t know where you’re getting nextOpenSlot but it has to be a game object in the scene for it to be a parent:

        GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        GameObject sphere2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        sphere2.transform.parent = sphere.transform;