Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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 ....
     
unityunity