Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Error when getting count of childs after set new parent to entity.

Discussion in 'Project Tiny' started by reallyhexln, Mar 26, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hi, guys!

    Is it expected behaviour?

    Code (JavaScript):
    1. this.world.forEach([game.Menu, ut.Entity], (menu, menuEntity) => {
    2.     let menuItemEntity: ut.Entity = ut.EntityGroup.instantiate(this.world, "game.MenuItem")[0];
    3.  
    4.     this.world.usingComponentData(menuItemEntity, [ut.Core2D.TransformNode], (transform) => {
    5.         transform.parent = menuEntity;
    6.     });
    7.  
    8.     let menuItemsCount: number = ut.Core2D.TransformService.countChildren(this.world, menuEntity);
    9. });

    If so, how to avoid such behavior?
     
  2. Pakor

    Pakor

    Joined:
    Feb 2, 2017
    Posts:
    32
    Yes, sadly this is expected behaviour. At the moment the only way I found to fix this is to run the instantiation of the children in a different world.foreach loop. And then in the next loop you can count them.

    Code (JavaScript):
    1. this.world.forEach([game.Menu, ut.Entity], (menu, menuEntity) => {
    2.     let menuItemEntity: ut.Entity = ut.EntityGroup.instantiate(this.world, "game.MenuItem")[0];
    3.  
    4.     this.world.usingComponentData(menuItemEntity, [ut.Core2D.TransformNode], (transform) => {
    5.         transform.parent = menuEntity;
    6.     });
    7. });
    8.  
    9. this.world.forEach([game.Menu, ut.Entity], (menu, menuEntity) => {
    10.     let menuItemsCount: number = ut.Core2D.TransformService.countChildren(this.world, menuEntity);
    11. });
     
    Last edited: Mar 27, 2019
    reallyhexln likes this.
  3. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Pakor, thank you for your reply. I will try to use this way.