#How do you schedule a IJobFor using the Length of a NativeList populated by another job

1 messages · Page 1 of 1 (latest)

elder escarp
#

I have a job that populates a NativeList. And I want to schedule a second IJobFor to run after the first, that operates on each element in that NativeList. Is there a way to do this?

dusky dawn
#

you use IJobParallelForDefer instead

#

and pass the list into the schedule instead of the length

elder escarp
#

I don't see it in Jobs or Collections

dusky dawn
#

it's in collections package now

#

it was previously in the standalone jobs package but htats been removed

#

and merged into collections

elder escarp
# dusky dawn

Wait what version of Unity is that. I am only seeing Collections 1.2.4 in the package manager in 2022.2. I don't see a 2.1.4

dusky dawn
#

are you on entities like 0.51 or something?

elder escarp
#

Ahh, enabling prerelease packages shows it

#

No, I am not using entities

dusky dawn
#

oh

#

yep ok

elder escarp
#

Ahh, I see it. Thanks @dusky dawn! I see it also takes a pointer to a int. Is there a way to use the NativeList.Length with it? Like doing NativeList.Length / 2?

dusky dawn
#

you just pass in nativelist

elder escarp
#

I know, I am asking if there is a way to instead use the length

dusky dawn
#

your problem is you don't know what the length is

#

How do you schedule a IJobFor using the Length of a NativeList populated by another job

#

this is exactly what it does

#

it reads the length once the job starts

#

not when you schedule it

#

so the previous job will have finished populating it and it will use the right length value

elder escarp
#

I mean that there are cases where I don't want to have the job do exactly the same number as there are elements in the list. Instead doing like 50% of the size of the list.

dusky dawn
#

i can't think of any way you could do that

#

without causing a sync

#

i guess

#

insert a job between the 2 and resize the lenght 😄

elder escarp
#

Hmm, looks like it uses NativeListUnsafeUtility.GetInternalListDataPtrUnchecked(ref list) to get the count, and the int* produces the same thing with var forEachListPtr = (byte*)forEachCount - sizeof(void*);

#

So looks like there might be a way... maybe... but this is too deep in to the pointer rabbit hole for my current knowlage haha

dusky dawn
#

i don't really understand how the code you posted there would help

#

you could allocate a pointer randomly and give it a value

#

but at that point you're doing nothing different than just ijobfor

elder escarp
#

I don't quite understand what void* is. But my thinking was if you could do some sort of math between them or add them together or something...

#

It isn't a big deal I don't think. I appreciate your help! 😄

dusky dawn
#

it's just a pointer where the length value is stored

#

but you can't do maths until after your other job has finished running