Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 GarrettJohnson · Dec 15, 2012 at 06:39 AM · loadingfilemaptextassettxt

Resources.Load not giving me all data for a .txt file

I created a map editor in Processing for my game (it's tile based) using two bytes (or two chars) per tile to store the data that I needed. Of course, this leads to a very illegible and unintelligible looking text file, but it has the data that I need.

I can load the file back into processing and regenerate the map just fine, but I can't get the same data into Unity.

I load the map file as a TextAsset so I can read the lines, but it always just says that my file is only one character long, which does nothing for me. Is Unity expecting some different format? I don't understand why it won't read it in like I can in processing. How can I get all of this data into Unity?

Thanks.

Comment
Add comment · Show 3
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 whydoidoit · Dec 15, 2012 at 07:05 AM 1
Share

Going to need to see the code you use to load that asset...

avatar image clunk47 · Dec 16, 2012 at 03:06 AM 1
Share

We need the script you are using in order to help you with a script that is not working as desired.

avatar image GarrettJohnson · Dec 16, 2012 at 09:41 PM 0
Share

I don't know what kind of code snippet you want. It's more of a question about the TextAsset class. I was literally just doing this:

TextAsset ta = Resources.Load("Levels/testmap") as TextAsset;

print( ta.text.length );

and it printed 1, which is not right.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GarrettJohnson · Dec 16, 2012 at 09:47 PM

I fixed it by using the .bytes member because apparently it has more information than .text?

Comment
Add comment · Show 3 · 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 kurifu · Dec 16, 2012 at 10:06 PM 1
Share

No, this really shouldn't happen unless something has been embedded at the top of your text file with a null character. $$anonymous$$aybe a bad UTF Byte Order $$anonymous$$ark? open up the source text document with a hex editor and check for any null character at the front of the document, don't be alarmed if you see a UTF Bo$$anonymous$$ as long as it meets the specification as explained here: http://en.wikipedia.org/wiki/Byte_order_mark

avatar image Bunny83 · Dec 16, 2012 at 11:18 PM 0
Share

I guess that the 2 bytes are not ascii characters so they get interpreted as UTF8 or Unicode characters. What kind of "data" did you store in the file?

The "text" property is meant to access text. If you store binary data in the file you have to use "bytes" of course.

avatar image yoyo · Dec 17, 2012 at 03:29 AM 0
Share

If there's a 0 byte in your data then in a text file it will be treated as an end of file marker. In a binary file it's fine. Using a text file for raw data can also cause trouble when characters used to mark end of line (carriage return and line feed) may get reinterpreted. Sounds like .text acts like a text file while .bytes acts like a binary file.

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reading Data generated in Processing from a TextAsset 0 Answers

How do I save game Data? 1 Answer

Loading a saved Game 1 Answer

Loading with binary formatter weird problem 1 Answer

How does a TextAsset work? 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