Replace a child gameobject by an other at runtime

I want to replace a child gameobject by an another one at the same level of hierachy.

I tried to copy the transform.parent value of the original object before instanciate a new one and copy the transform on it then destroy the primary child object. But it doesnt work.
The instanciate object is not instanciate as a child and i got a MissingReferenceExeption because i try to access a destroyed object.

here is my code :

using UnityEngine;
using System.Collections;

public class EditorManager : MonoBehaviour {

void StartPlaceObjs () {
	GameObject mybutton;
	GameObject myref;

	myref=GameObject.Find("Button_Objects");
	mybutton=EditorData.editorPrefabs[7];
	
	mybutton.transform.parent = myref.transform.parent;
	
	GameObject.Instantiate(mybutton);	
	GameObject.DestroyImmediate(myref);	
	}
}

You’re trying to set the prefab’s parent! Get a reference to the newly created object, then set its parent:

  ...
  void StartPlaceObjs () {
    GameObject mybutton;
    GameObject myref;

    myref=GameObject.Find("Button_Objects");
    mybutton=EditorData.editorPrefabs[7];
    // get a reference to the instantiated object:
    GameObject newObj = GameObject.Instantiate(mybutton) as GameObject;
    // copy parent (maybe you should copy the position and rotation as well)
    newObj.transform.parent = myref.transform.parent;
    GameObject.DestroyImmediate(myref);    
  }
}