NativeSlice triggers "InvalidOperationException: The native container has been declared as ReadOnly"

I’m trying to call UnsafeUtility.MemCpy(), and I’m using NativeSlice on the [ReadOnly] array.
Unfortunately this seems to trigger the exception “InvalidOperationException: The native container has been declared as [ReadOnly]”

Is this a bug, or am I misunderstanding what Slice is doing?

note: as a workaround I’m just using [NativeDisableContainerSafetyRestriction] and everything seems fine, just seems like a bug that [ReadOnly] doesn’t work and I worry if any optimizations are disabled from doing this.

Show code?

You might have to use GetUnsafeReadOnlyPtr instead of GetUnsafePtr.

1 Like

Ah nice! I missed this somehow. What’s the reason for this separation?

For preventing you shooting in a leg, from time to time :slight_smile:

2 Likes