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
#Reading a TXT File - data flow
1 messages · Page 1 of 1 (latest)
You can't really do what you want in Burst, just load it outside of burst.
However you can do it in separate threads if you use something like
https://docs.unity3d.com/2022.2/Documentation/ScriptReference/Unity.IO.LowLevel.Unsafe.AsyncReadManager.html
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
Thanks! Yeah that's exactly what I was assuming. I'll give this a try
I blame the first paragraph of the docs
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
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
@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.
as string? you'd have to convert the bytes
but the ReadHandle has
GetBytesRead
GetBytesReadArray
Ooh, so far Burst hasn't liked converting bytes to strings. Something about using a managed function inside of Burst?