Instantiating unique Prefabs to unique child objects in C#

/I’m trying to instantiate multiple prefab “doors” to multiple hallway sections in the scene. Each hallway section has it’s own child object that serves as potential spawn point for a prefab “door”. I can spawn multiple prefab “doors” to the same child object of one hallway section, but can’t get prefab doors to spawn for child objects of multiple hallway sections. My goal is to generate a unique prefab door for each hallway section in the scene. Any help and or feedback would be fantastic…My code is below:/

		for (int i = 0; i < currSections.Count; i++) 
			// Identifying the first section that needs a ceiling door.

			GameObject activeSect = currSections *;*
  •  	// Print the section that is chosen.*
  •  	Debug.Log ("Active section: " + activeSect);*
  •  	// Identifies the child of the section that will be the spawn point for the ceiling door.* 
  •  	GameObject ceilingSpawn = activeSect.transform.GetChild (1).gameObject;*
  •  	// Add the ceiling door spawn point to a list.*
  •  	ceilingSpawnPts.Add (ceilingSpawn);*
  •  	// Print the gameObject chosen for the ceiling door spawn point.* 

_ Debug.Log ("The spawn point is " + ceilingSpawnPts );_

* // Chooses a random ceiling door from a list.*
* int ceilIndex = Random.Range (0, ceilingDoors.Count);*

* // Identify the chosen ceiling door gameObject.*
* GameObject currCeil = ceilingDoors [ceilIndex].gameObject;*

* // Print the name of the active GameObject.*
* Debug.Log ("The chosen ceiling door is " + currCeil);*

* Debug.Log ("i = " + i);*

* // Add the chosen ceiling door to the current ceilings list.*
* currCeilings.Add (currCeil);*

* // Print the name of the active GameObject.*
* Debug.Log ("The added ceiling door is " + currCeil);*

* // Clones the ceiling door GameObject and places it into the scene at the spawn point.*
* GameObject ceilDoor = Instantiate (currCeil, ceilingSpawn.transform.position, Quaternion.identity) as GameObject;*

* }*

That is quite verbose. At a glance it looks like you need to set the parent transform in your prefab instantiation to ceilingSpawn.transform.

Yeah, sorry for the verbosity. Thanks for your help. I tried that but received a “Setting the parent of a transform which resides in a prefab…” error. I realized that the hallway sections are also prefabs, so I have a nested prefab problem. I’m going to research some of the plugins available, but please let me know if you have a better solution. Thanks again!

I added this line at the end of that method and it seemed to work just fine for me. Let me know if that’s not the desired functionality:

ceilDoor.transform.parent = ceilingSpawn.transform;