I use UnityWebRequest to download a NativeArray, and use in in Jobsytem, is there way to read string from NativeArray?
[ReadOnly]
public NativeArray<byte> SrcBytes;
byte srcNameLen = SrcBytes.Slice ( offset, 1 ).SliceConvert<byte> ()[ 0 ];
offset += 1;
NativeSlice<byte> srcName = SrcBytes.Slice ( offset, srcNameLen ).SliceConvert<byte> ();
offset += srcNameLen;
the scrName is about the string , how to convert to string in mainthread?
Ok, but i found in job system that don’t allow managed types, so how do i return string to main thread?
You run the Job from the main thread. I suppose that’s where you also pass in the NativeArray (or Slice). So after the job is complete, you’d get the job.srcName (assuming it’s a public field or property) and use that.
thanks reply,
I didn’t know how long it was until I read it, so how to delcare the variable srcname in job ?
It sounds like what you really want is FixedStringXBytes from the Collections package.
ok, thanks a lot, i’ll check this out