Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Foreach loop not going through all elements

$
0
0
Hello! I am having an issue with this piece of code: foreach (Transform child in transform) { if (child.tag == "Grass") { child.transform.parent = grassList.transform; } if (child.tag == "Swamp") { child.transform.parent = swampList.transform; } if (child.tag == "Mountain") { child.transform.parent = mountainList.transform; } } In theory it should go through every child in the current gameobject, and assign them their proper parents, however, it is only partially doing so. If the foreach loop is run several times (Through the update function, or manually calling it), it eventually manages to assign the correct parent to all the children. Is there any way for the foreach loop to actually get all the children in one go? Mind you, we are talking about 100+ gameobjects at once.

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>