Timeline for Why does this Unity code work as expected only with the while loop?
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 30, 2013 at 2:59 | comment | added | Sean Middleditch | You're iterating over a collection while removing elements from it (which is what changing its parent will do). This is illegal and produces undefined behavior (or oddness like only iterating over a subset of all items in the collection) for most data structures in almost all languages. This is a basic programming question, nothing super specific to games, C#, or Unity. | |
Mar 28, 2013 at 17:11 | comment | added | user15805 | Technically, if Unity did not suppress the thrown exception, you would've noticed the issue right away. The answer requires knowledge of this (Unity) bug so, in my opinion, this is the place for the question. | |
Mar 28, 2013 at 16:42 | comment | added | Matt Bond | Seeing the answer, I'm inclined to agree. When I asked it I thought I was falling foul of a Unity specific subtlety so I chose to ask here. I always find it's a tough call whether to ask questions like this here or on SO though. | |
Mar 28, 2013 at 16:34 | vote | accept | Matt Bond | ||
Mar 28, 2013 at 16:29 | comment | added | House | You're getting good answers here, though I believe this belongs on stackoverflow. | |
Mar 28, 2013 at 16:20 | review | Suggested edits | |||
Mar 28, 2013 at 19:13 | |||||
Mar 28, 2013 at 16:18 | review | Close votes | |||
Apr 5, 2013 at 3:02 | |||||
Mar 28, 2013 at 15:37 | answer | added | user15805 | timeline score: 13 | |
Mar 28, 2013 at 15:01 | history | edited | Matt Bond | CC BY-SA 3.0 |
added 49 characters in body
|
Mar 28, 2013 at 15:00 | comment | added | Matt Bond |
The expected output: parent all children to obj. The output without the while loop: only some children are parented to obj, some remain parented to transform
|
|
Mar 28, 2013 at 14:58 | comment | added | user15805 | "With the while, it works exactly as expected." - Which is? What is the expected output? | |
Mar 28, 2013 at 14:52 | history | asked | Matt Bond | CC BY-SA 3.0 |