#Modifying DynamicBuffer of child entity in parallel job

1 messages · Page 1 of 1 (latest)

opaque venture
#

Hi all! I'm a newcomer to DOTS and ECS and I'm running into a problem, and I was wondering if anyone here might have any advice?

Is it possible to gain read-write access to a DynamicBuffer during a parallel job without passing it in as a parameter? I have a parent entity that the job operates on, but during the logic, I need to alter a DynamicBuffer belonging to a child entity of that parent.

Unity's built-in safety systems are preventing me from using a BufferLookup with read-write permission in a parallel job to prevent multiple threads from trying to write to the buffer simultaneously, but I believe that each individual child's DynamicBuffer will only be accessed once, so unless I'm mistaken there shouldn't be a risk of that happening.

I'm unfamiliar with other ways to access a DynamicBuffer of a different entity other than a BufferLookup, and my attempts at searching and asking so far have not led me to figuring out how to remedy this or work around it. Any assistance is appreciated!

clear star
#

Not sure what you mean by passing it in as a parameter but theres NativeDisableContainerSafetyRestriction if you want to disable safety but sounds like maybe you only need to allow writing to the container from multiple threads via NativeDisableParallelForRestriction (and of the two ive only used the latter)

opaque venture
#

Forgive me for being a bit unclear, I can definitely struggle with finding the language I need to appropriately communicate what I'm struggling with, especially since I'm a newcomer both to DOTS and Unity in general and I can get my terms mixed up.

When I mean not passing it as a parameter, I mean accessing a DynamicBuffer other than one specified in the parentheses of the Execute() method. I believe what I am trying to do is to access a DynamicBuffer belonging to an Entity other than the ones that contain all of the components specified in the Execute() method.

In this case, I know exactly which Entity that is: it's a child entity of the one(s) being operated on by the Execute() method, and I have the appropriate data to know which Entity it is that I want to access. I'm just not sure how to access its DynamicBuffer with read-write permissions.

I've tried putting [NativeDisableParallelForRestriction] before the BufferLookup declaration in the job, but it doesn't stop me from getting this error:

"InvalidOperationException: The BufferLookup<SpringsElement> has been declared as [ReadOnly] in the job, but you are writing to it."

shrewd sorrel
#

Well, don't mark it as ReadOnly. 🤔

opaque venture
#

Unless I'm making quite a silly mistake, I don't believe I'm marking it as ReadOnly. It seems to be defaulting to it, and I'm not sure how to change it.

#

Nevermind!

#

I am making quite the silly mistake!

#

Thank you!

#

I, in fact, was marking it as ReadOnly way back in the System, not in the Job itself!

#

Wow, I feel really silly. Thank you!

#

Yup, in the GetBufferLookup I was marking I had isReadOnly set to true, and then I forgot completely that ReadOnly was specified there.

#

Thank you all!