Two jobs one hashmap?

Hi,

to make it short:

//In Start:
_cache= new NativeHashMap<int3, Entity>(300, Allocator.Persistent);


//In Update:
var cache = _cache;

//job1
Dependency = Entities.Foreach(() => {
    cache.add(xyz);
    Debug.log(cache.count()); //returns the number as expected
}).Schedule(Dependency);

//job2
Dependency = Entites.Foreach(()=>{
    Debug.log(cache.count()) // returns 0
    if(cache.hasKey()){
        //etc
    }
}).Schedule(Dependency);

Why is the hashmap is empty in the second job? How would i do something like that? Eg collecting data in job 1 then using this in job 2 ?

EDIT: i feel so bad again, i spend like 10 minutes on this question and the moment i hit play, i get the solution.

It was a user error :slight_smile: i was resetting the cache for no reason at a different part of the code

Just a side note,
with Entities.Foreach you don’t need
Dependency = and .Schedule(Dependency)
Dependency is done in “background”.