Parent/un-parent In Javascript

Discussion in 'Technical Discussion' started by 5petersonzachary, Dec 10, 2020.

  1. 5petersonzachary

    5petersonzachary Serious Boxer

    Joined:
    Jan 23, 2016
    Messages:
    569
    Likes Received:
    169
    Does anybody know how I can un-parent and parent 2 objects in javascript? Say the player clicks on the screen and I want to make the player be a parent to another object in the scene, and then when the player lets go I want it to un-parent the object.

    Thanks!
     
  2. 5petersonzachary

    5petersonzachary Serious Boxer

    Joined:
    Jan 23, 2016
    Messages:
    569
    Likes Received:
    169
    Preferably this node would have inputs designated to trigger the parent/un-parenting. I hope this makes sense lol
     
  3. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Hey, thanks for asking,

    The quick answer is no, you cannot do it because the API currently does not support the removeChild method you only have the addChild method available.

    The long answer is something like this:
    - You can add children's to a specific object triggered by an external input
    - To remove it just clone that object and than remove the parent and add that cloned version of your character to your next parent
    - Repeat both steps to get a constant result
     
    5petersonzachary likes this.
  4. 5petersonzachary

    5petersonzachary Serious Boxer

    Joined:
    Jan 23, 2016
    Messages:
    569
    Likes Received:
    169
    Thanks!
     

Share This Page