Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Baalrukh · Jun 22, 2011 at 10:13 AM · resourcesbinary

Yet another binary file loading question

I am currently trying to port an existing application to Unity, and when it comes to resources loading, problems arise... I fumbled for a while until I found about the ".bytes" extension required to load binary files and ... it still didn't work. My files begin with a magic number and a version number like follows :

 0x504D425200000200  (in hexa)
 which can be read in ASCII as : PMBR....  (the last 4 characters are not writable)

when I load a file, I obtains only the first 4 bytes.

A few experiments later, I tried on a hunch to change the first byte to a hex value > 128 and it finally worked !

But this solution feel dirty, I have to modify the content of my resources (in addition to changing the extension) and what guaranty do I have that it will work with all my files ?

Does anyone know of a true solution to this problem ?

Edit :

To clarify my question, here is what I think happens :

  • If a file starts with ASCII characters (< 0x80), Resources.load("myFile", typeof(TextAsset)) loads the file into a string and TextAsset.bytes returns the bytes of the string. So if a file contains 0x0000 (or just 0x00 ?) the file is cut when loaded to a string and so, TextAsset.bytes returns only the bytes available in the string (0x504D4252 in my case).

  • If on the contrary the file starts with a non-ASCII character (> 0x80), it is handled as a binary file and there is no problem when loading it

Hava you already encountered such behavior ? how did you handle it ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 22, 2011 at 12:24 PM

Depending on what system you work it's a difference between little-endian and big-endian format.

If you read the first 4 bytes as an int32 on a "normal" x86+ architecture you will have the little-endian format. So the first 4 values(0-3) as one int32 will look like this:

 0x52424D50

The next 4 bytes (4-7) look like this (if that's the true hex representation):

 0x00020000

Another thing:
When this "PMBR0020" is the ascii representation the last 4 bytes will be

 0x30323030

0x30 == 48(dec) == "0"

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Baalrukh · Jun 22, 2011 at 03:13 PM 0
Share

I messed up in my notation of the file, my issue is not about endianess or ASCII representation, but about number of bytes obtained with TextAsset.bytes I edited my question to make it easier to understand (I hope)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Reading binary file from Resources folder 2 Answers

Load binary files from Resources 1 Answer

Can i load my binary with Resources.Load()? 1 Answer

Baffling Resources.Load by playerprefs string problem. 1 Answer

Prefab cant istiantiate through recources.load? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges