Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Changing parent of an instantiated entities or existing entities

Discussion in 'Project Tiny' started by Zoelovezle, Feb 11, 2019.

?

Is it possible ?

  1. Yes

    0 vote(s)
    0.0%
  2. No

    0 vote(s)
    0.0%
  1. Zoelovezle

    Zoelovezle

    Joined:
    Aug 7, 2015
    Posts:
    13
    I am trying to create a grid based game on canvas .
    A simple solution was instantiate multiple canvas groups containing one button each and then attach that to canvas camera .
    But i am trying to make it more elegant as i dont want to instantiate multiple canvases and rather just have singular canvas and have buttons as child of it .
    So far exploring , i found out that the TransformNode attached to every child as the reference of its parent entity . Removing it and adding again in runtime or modifying the reference of TransformNode throws error "The component already exists"

    So i removed the transformnode manually while building and in runtime
    Code (JavaScript):
    1. this.world.setOrAddComponentData(blockEntity , new ut.Core2D.TransformNode(canvasEntity))
    Its runs but shows blank and since i can't actually inspect hierarchy i cant know for sure if it actually setting the parent as canvas entity or not
     
  2. Zoelovezle

    Zoelovezle

    Joined:
    Aug 7, 2015
    Posts:
    13
    The problem was scaling . Resolved it by scale back to (1,1,1) after setting the parent .
     
  3. ronblockparty

    ronblockparty

    Joined:
    Oct 13, 2018
    Posts:
    6
    Hey @Zoelovezle, sounds like you solved the issue, but for future purposes, I recently found out that if you pause execution in the editor while the game is running in your browser, it populates the hierarchy with entity and component values so you can inspect and debug them.

    See here: https://forum.unity.com/threads/help-debugging.608503/

    Hope that helps!
     
    Zoelovezle likes this.
  4. ronblockparty

    ronblockparty

    Joined:
    Oct 13, 2018
    Posts:
    6
    By the way, I found that setting the TransformNodeComponent's parent property isn't actually causing entities to become children of the parent. My code looks like this:

    Code (CSharp):
    1. const transformNodeComponent = this.world.getComponentData(blockEntity, ut.Core2D.TransformNode);
    2. transformNodeComponent.parent = this.world.getEntityByName("Board");
    3. this.world.setComponentData(blockEntity, transformNodeComponent);
    Inspecting the hierarchy, blockEntity doesn't become a child of the Board entity. Still trying to find a fix for this.