[Editor Scripting] Instantiating array of game objects can't get parent transform

Hi, so I want to instantiate array of game objects via editor scripting. Now the problem is when I instantiate the prefab it lost it’s parent in hierarchy. When I’m instantiating like the script below it works just fine :

for(int i = 0; i < 20; i++){ //_dTarget.halfLength; i++){
    GameObject a = (GameObject)PrefabUtility.InstantiatePrefab(_dTarget.wallTile);
    a.transform.parent = goTarget.transform;
}

but if I instantiating like this :

GameObject[] testG = new GameObject[20];
for(int i = 0; i < 20; i++){
    testG[i] = _dTarget.wallTile;
}
for(int i = 0; i < 20; i++){ //_dTarget.halfLength; i++){
    GameObject a = (GameObject)PrefabUtility.InstantiatePrefab(testG[i]);
    a.transform.parent = goTarget.transform;
}

they lost their parent and instantiated outside the parent : Upload and share screenshots and images - print screen online | Snipboard.io
Any ideas why this happens ?

Bump !

It would probably be handy to see the rest of the script - if you could post a cut-down project which shows the problem happening I’m willing to have a look at it for you.

It’s already resolved. I just have to simply put PrefabUtility.DisconnectPrefabInstance before we set the parent.