Author Topic: Child/Parent relationship  (Read 1832 times)

Offline nathan

  • byte
  • *
  • Posts: 15
    • View Profile
Child/Parent relationship
« on: April 11, 2013, 12:40:47 am »
Why is there no method like
Code: [Select]
Object3D[] getChildren()but there is
Code: [Select]
Object3D[] getParents()
I have a group of objects (From another example, it is a car and its 4 wheels).  I want them all to move together, so I add them as children to another object, which is a collision mesh.  And, now I would like to pass the reference to the outer object around, and change all the children simultaneously.  For instance, I want to change visibility, or remove them from the world.

All I can think of doing is extend the Object3D class, override the addChild() function to also add the child to a list.  Then add a getChildren() function that just returns that list as an array and use this in my own functions. 

I just don't understand why there is no getChildren() function?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Child/Parent relationship
« Reply #1 on: April 11, 2013, 07:48:02 am »
Because there's no cyclic reference. A child knows its parent(s). A parent has no idea about its child(s). If you need that, you can extend Object3D and add it yourself.

Offline nathan

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Child/Parent relationship
« Reply #2 on: April 11, 2013, 07:13:06 pm »
Thank you,
I will do just that