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

Pushing entities in a array of Entities Reference

Discussion in 'Project Tiny' started by Zoelovezle, Mar 2, 2019.

  1. Zoelovezle

    Zoelovezle

    Joined:
    Aug 7, 2015
    Posts:
    54
    I am trying to push instantiated entities into a array of entity reference attached to component . So far it's just not working .

    Code (CSharp):
    1. this.world.foreach([game.Pooling] , (pool)=>{
    2.     let clone = ut.EntityGroup.instantiate(this.world , game.ItemGroup)[0]
    3.     pool.entities.push(new ut.Entity(clone.index , clone.version))
    4. })
     
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    This has worked for me at times, maybe you could give it a try:


    Code (CSharp):
    1. this.world.foreach([game.Pooling] , (pool)=>{
    2.     let clone = ut.EntityGroup.instantiate(this.world , game.ItemGroup)[0]
    3.     pool.entities = this.addToArray(pool.entities, new ut.Entity(clone.index , clone.version));
    4. })
    5.  
    6. /** Copies immutable array, adds specified element to it and returns the new array */
    7. addToArray(original: ut.Entity[], newElement: ut.Entity): ut.Entity[] {
    8.     let result: Array<ut.Entity> = original;
    9.     result.push(newElement);
    10.     return result;
    11. }
     
  3. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    I believe the reason its not working is because you have to add the entities to the array outside of the foreach and not inside of it