Reading binary Resources

Hi,

I am trying to read a binary file from the resources. To do this I call the Resources.Load(…) function getting a TextAsset. Since here everything clear. But then how can I open it to read? I tried all combinations to be able to read it with the BinaryReader tool but no way. Anybody knows the exact combination?

There is actually a TextAsset class. It has properties for getting either the text or the raw bytes from the asset.

Ok but how can I get a Stream from that? I want to do something similar to:

 Stream s = new FileStream("Assets//Resources//enemy_sequences_bin.bin", FileMode.Open);
        BinaryReader br = new BinaryReader(s);

        int iCount = br.ReadInt32();

Ok I found the solution:

Stream s = new MemoryStream(asset.bytes);

but now the when I call:

TextAsset asset = Resources.Load("enemy_sequences_bin") as TextAsset;

it returns me null. Do I have to set a specific name for binary files located on the Resource folder?

I think the file suffix has to be .txt regardless of the content of the file.

1 Like

That was the problem :slight_smile: Thanks!!

Suffix (file extension) has to be “.bytes”

1 Like

10 years! A new record I believe.

8 Likes