Search Unity

Runtime Parenting

Discussion in 'Scripting' started by marty, Jul 1, 2005.

  1. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    How do I make one object a child of another in JavaScript?

    And, how do I then un-child an object in JavaScript?
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    myobject.transform.parent = otherobject.transform;

    myobject.transform.parent = null;

    *hopes he got his JS syntax right*

    -Jon
     
  3. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Ohh, in the object's Transform properties.

    Now, why didn't I look there?

    :wink:

    Thanks!
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Yeah, I think it makes sense there when you think about it. I don't think they can just have the parent aliased so you could also do myGameObject.parent , because that'd assume every game object has a Transform component... which isn't totally the case.

    hmm

    -Jon
     
  5. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Yeah, it seems logical enough. After all, translating, rotating and scaling are the only things you do with whole hierarchies. I just never thought of that until now.

    I wonder though, is there some non-transform-related thing we might want to do to a group of objects based on their hierarchical relationship?

    Hmm ....