Why does the foreach loop not return the Transform on Path(0)?

I’m a little confused on the logic of why the 3 waypoints get returned in the for loop.

foreach(Transform child in pathPrefab.transform)

Why does pulling each transform from pathPrefab.transform only return the 3 child transforms, and not the transform on Path(0) itself?
To me it looks like “pathPrefab.transform” would be a reference to the transform itself on Path(0), and not include the children in the hierarchy.

Thanks for the help.

Hi AcidMonkey,

There is no inherent logic behind the code. The pathPrefab.transform contains information about the children of the game object/Transform object because the Unity programmers who created the Transform class defined it this way. We cannot know how something works just by looking at names. We can only assume. That’s why we always have to take a look at the description in API hoping that it provides all relevant information.

Did this help? :slight_smile:

See also:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms