#Reading a TXT File - data flow

1 messages · Page 1 of 1 (latest)

deft oxide
#

Using Unity's ECS "StateChange" Sample, I'm reading in a basic TXT file (Rows are X,Y,Z values), and creating a cube with the position of each row.
I'm able to use the StreamingAssets path in the Editor, although when I try to Build it gives the error that StateMachineValue.InitSystem.GetStreamingAssetsPath() is not supported. Following some advice online I created a separate [BurstDiscard] method to run that in, but still no luck. Samething with StreamReader, ReadAllLines, ReadAllText, and FileInfo so far. In general, what's the best way to read file data into DOTS, and create GameObjects out of it? I made a fork of the ECS Samples, and here is the InitSystem.cs script with the LiDAR file reading component: https://github.com/EarthAdam/EntityComponentSystemSamples/blob/master/EntitiesSamples/MiscellaneousEntities/Assets/Scripts/Systems/InitSystem.cs

GitHub

Copy of Unity's ECS Samples for experimentation. Contribute to EarthAdam/EntityComponentSystemSamples development by creating an account on GitHub.

dire veldt
#

Also BurstDiscard will not help you here, it just means it won't run. For some reason people got the idea that adding BurstDiscard will just mean that burst will jump out of burst to execute the code or something, which is wrong.

#

You can do something like this by passing in a FunctionPointer but for this case that seems a bit excessive

deft oxide
#

Thanks! Yeah that's exactly what I was assuming. I'll give this a try

smoky vine
#

it's kind of misleading

#

you have to read the comment in the first example to actually understand it

#

They should just add a line saying that it doesnt allow execution of non burst code inside a bursted function

deft oxide
#

Any tips on making OnUpdate asynchronous so it has to wait for that reading method to finish? I've tried a few approaches, but then it doesn't want to take state as an input parameter, which ISystem seems to need

deft oxide
#

@dire veldt for the AsyncReadManager, how do I finally save the file contents to a string? All I see in here is ways to check the state of the read, the size of it, type, etc. but nothing that just gives me the resulting data.

dire veldt
#

as string? you'd have to convert the bytes

#

but the ReadHandle has
GetBytesRead
GetBytesReadArray

deft oxide
#

Ooh, so far Burst hasn't liked converting bytes to strings. Something about using a managed function inside of Burst?

dire veldt
#

you can't use strings in burst

#

any of those strings you might use for debug log etc are just magically converted into fixedstrings

#

you could write a converter from bytes -> fixedstring

#

(could well be built in already)

deft oxide
#

I'm able to save it as a NativeArray<float3> which Burst is okay with

#

Just need to get back to a state where I can GetBytesRead. Too far down a ChatGPT inspired rabbit hole lol