Search Unity

Can't Call EntityManager.GetBufferFromEntity()

Discussion in 'Entity Component System' started by JakHussain, Jul 10, 2019.

  1. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    I'm trying to set the value of a BufferFromEntity object using GetBufferFromEntity(). My code is NOT running in a JobComponentSystem because my job isn't supposed to run on update. Just when I trigger some event do I want to schedule my job for that frame only. So I don't have access to JobComponentStystem.GetBufferFromEntity().

    I looked into the source code and found that JobComponentSystem just wraps around EntityManager.GetBufferFromEntity() so I thought I'd just use that and cut out the middle man. To my surprise, The documentation and source code for EntityManager has absolutely no reference to the method I'm looking for and I can't call it.

    This is according to preview 33.

    Does anyone have any suggestions? I would think that there would be some way to call a method in a JobComponentSystem on a single given frame but I can't seem to find any examples.

    My usecase is that I want to schedule my job on canvas button press. But the Button component needs a reference to a monobehaviour in order to do that.
     
  2. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Any ideas?
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    You shouldn't be using GetBufferFromEntity unless you're passing it to a job in JobComponentStystem due to dependency handling. GetBufferFromEntity doesn't just call EntityManager.GetBufferFromEntity it adds a dependency to the safety system on that component.

    And from the sounds of what you're doing you should still be scheduling your job in a JobComponentStystem that only updates conditionally when an event is present, something like.

    this.RequireForUpdate(this.EventQuery);
     
  4. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    If I'm understanding the docs correctly, RequireForUpdate makes it so that OnUpdate will only run when there are entities in the world that satisfy the query. But in my case, my queries are always in existence. I just want to run the job once by clicking a button which calls a method in a monobehaviour which somehow calls a method in my JobComponentSystem. Am I missing something?
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Yes, that's why the RequireForUpdate isn't on your entities, but on an event entity.

    i.e.

    EntityManager.CreateEntity(typeof(TriggerEvent));

    and the EventQuery is just a All = new[] { ComponentType.ReadOnly<TriggerEvent>() }

    This way system will only run when triggered.
     
    eizenhorn likes this.
  6. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    I'm sorry I'm just finding it hard to understand what you mean by an event entity? Are you suggesting to tag all my entities with some empty component data and query for those? And then after the job is complete, remove the componentdata tags so that the component system no longer runs?
     
  7. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    On button click create entity which will represent event and write system which will handle only this event entities and doing stuff with buffer.
     
  8. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Is there a particular sample available that does this so I can look into it more myself? I haven't seen this approach done before.
     
  9. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Some of the physics samples kind of demonstrate it but they are pretty complicated for just beginning dots. Eizenhorn described exactly what you need to do. Which part of it are you unclear about?