Get a Buffer from an Entity in a Job

Hello again,

Once I understand how DOTS works I am going to be SO happy. Anyway…

I have two entity archetypes; “Autos” and “Roads” Roads have Lanes, and Lanes have Points along their length. Each Auto is on one a specific Road and Path, and has a ref to this road as an entity. So, I have a job that iterates through all tagged Autos and get’s it’s “child” road entity, here is where the problem occurs. I am attempting to get the Buffer from the Road Entity. It is my understanding that inside a job the function: “GetBufferFromEntity” to do this, Dynamic Buffers | Package Manager UI website

However, the following line causes an editor exception:

 var lookup = GetBufferFromEntity<LanePointsComponent>();

Exception: An object reference is required for the non-static field, method or property. JobComponentSystem.GetBufferFromEntity

Um, what? This is the EXACT code from the documentation, so what dumbass thing am I doing wrong?

Thanks kindly.

I think you need to take whatever data you need from that buffer OUT of a job, then you can use the data in a job
Plenty of stuff is not available on jobs

Can you post your Job and update, how it look like?

You job part in update should be,

lookup = GetBufferFromEntity<LanePointsComponent>() ;

Then in job itself, before execute,

public BufferFromEntity <LanePointsComponent> lookup ;

Thanks kindly, however I cannot see a way to do that. Autos don’t have a set path, at each update I need to check if they have reached their current Destination_Point, and if so query the road for the next point. Even if I moved the entire path to the Auto entity, I still need the path points… or maybe you have a better idea, which I am ALL for… on my own I haven’t been able to figure a way out of this relationship issue.

So then, GetBufferFromEntity is not called within Execute, but is instead placed outside and is a parameter to the job like ComponentDataFromEntity. Is that correct?

In Execute, you need pass entity to get Dynamic buffer.
Like

DynamicBuffer <LanePointsComponent> buffer = lookup [my entity] ;

See for example

As is none updated example, you need replace IJobProcessComponentDataWithEntity, with IJobForEachWithEntity.

There are also other ways, But that is general concept.

2 Likes

Ah, an example, thank you, thank you, thank you.