Search Unity

Getentities -> Foreach ??

Discussion in 'Entity Component System' started by Delphic_, Apr 10, 2019.

  1. Delphic_

    Delphic_

    Joined:
    Apr 23, 2018
    Posts:
    39
    Hi,
    how would i fix this, it tells me to use Entities.ForEach, but i dont find a way how to write it ?

    public class MySystem : ComponentSystem {

    private struct Filter {
    public Transform transform;
    public TilePrefabComponent tilePrefabComponent;
    }

    protected override void OnUpdate() {
    foreach (Filter entity in GetEntities<Filter>()) {
    entity.transform.position = entity.tilePrefabComponent.position;
    }
    }
    }

    thank you
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    You can erase your Filter struct. Just use:

    Code (CSharp):
    1. protected override void OnUpdate() {
    2.     Entities.ForEach((Transform transform, TilePrefabComponent tilePrefab) => {
    3.          //your code here
    4.     });
    5. }
     
    Delphic_ likes this.
  3. Roycon

    Roycon

    Joined:
    Jul 10, 2012
    Posts:
    50
  4. StefanaUnity

    StefanaUnity

    Joined:
    Apr 9, 2019
    Posts:
    18