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

How would I check if an EntityGroup is loaded? How would I unload/destory an EntityGroup?

Discussion in 'Project Tiny' started by tomny, Jan 19, 2019.

  1. tomny

    tomny

    Joined:
    Sep 12, 2015
    Posts:
    16
    I'm trying to remove an EntityGroup, and it works for the most part but sometimes I still see it.

    I got this from one of the MatchThree examples

    Code (JavaScript):
    1.  
    2. let entity = this.world.getEntityByName(name);
    3. if (this.world.exists(entity)) {
    4.       ut.Core2D.TransformService.destroyTree(this.world, entity);
    5.        ut.EntityGroup.destroyAll(this.world, "game." + name);
    6.         //ut.Tweens.TweenService.removeAllTweensInWorld(this.world);
    7. }
    8.  
    (not sure what tweens do but works the same with/without)

    I instantiate like so
    Code (JavaScript):
    1.  
    2. public spawnGroup(name:string){
    3.             // spawn the Result
    4.             //entities.game.Menu.load(this.world);
    5.             ut.EntityGroup.instantiate(this.world, "game." + name);
    6. }
    What are the differences between instantiate and load?


    I'm trying to see if I actually destroy these Entity Groups but I dont know how to check if they are loaded.
    Is there a better way of destroying EntityGroups?
     
  2. tomny

    tomny

    Joined:
    Sep 12, 2015
    Posts:
    16
    Also Is there a way to see all the code functions and stuff? I'm using visual studio and usually when I do "ut.EntityGroup." after the "." it would show all the possibilities, but for typescript it isn't working.

    There really isn't enough documentation for Tiny so it's really hard for me to figure things out :/
     
    Scorch32 likes this.
  3. Nkon

    Nkon

    Unity Technologies

    Joined:
    Jun 12, 2017
    Posts:
    65
    Hi there,

    In order to destroy all EntityGroups with a specific name, this should be all you need:
    ut.EntityGroup.destroyAll(this.world, "game.TestGroup");


    Just replace the "game.TestGroup" with whatever name you have given to the EntityGroup. By default all the names are prefixed with "game.".

    If you wish to destroy the entities of a single EntityGroup, instead of all groups with the same name, you need to store a reference to the entities inside the group when instantiating it.

    Like this:
    Code (JavaScript):
    1. public newEntities;
    2.  
    3. public spawnGroup(name:string) {
    4.     this.newEntities = ut.EntityGroup.instantiate(this.world, "game." + name);
    5. }
    6.  
    7. public deleteGroup() {
    8.     this.newEntities.forEach(element => {
    9.         if (this.world.exists(element)) {
    10.             console.log("Destroying " + this.world.getEntityName(element));
    11.             ut.Core2D.TransformService.destroyTree(this.world, element);
    12.         }
    13.     });
    14. }
    I'm not sure about the problem with regular Visual Studio, but Visual Studio Code has been working fine for us, and it supports IntelliSense (aka code completion).

    Cheers!
     
    tomny and abeisgreat like this.