Search Unity

multiple instances of thingA are looking for an instance of thingB they can use exclusively

Discussion in 'Entity Component System' started by Mordus, Jan 9, 2020.

  1. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
    Lets say you have a game like rimworld. Multiple characters needs to find some wood to use for something, so they each find the nearest wood item to them and reserve it so they can go grab it without anyone else taking it. How would you achieve this in ECS.

    If you use a ReservedBy component on an item to indicate that it's reserved by a character then you can have your job only search items that aren't reserved. But when the job runs with multiple characters the components wouldn't be added until the command buffer runs, so multiple units might reserve the same item. You could have a Reservable component (with an entity field) thats always on the item and check whether a character entity is written into it which would allow you to write into it from a job without waiting for a sync point to take effect, but then you can't filter items by whether they've been reserved or not.

    How would you do this. this kind of "multiple instances of thingA are looking for an instance of thingB they can use exclusively" scenario is coming up a lot for me.
     
  2. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,269