Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 frjtrifork · Aug 10, 2015 at 12:40 PM · texture2dtextasset

Loading .bytes resource as TextAsset to get byte[]

I have a number of files that I need to embed into my application without modification (target platform is Android). I have Unity Pro.

At runtime the files need to be transferred to another device that I connect to using Bluetooth.

The files contain raw graphics in a custom format - the format is quite close to tiff but not quite tiff. I have no use for anything but the raw content of the file as a byte array.

I have 129 of these files - I have renamed the extension for all of them to .bytes (which should be supported by TextAsset) and put them in a Resources folder inside my Assets folder and load them using Resources.Load(path).

This works for 59 of them - they come back as TextAsset from which I can get the content of the resource as byte[]. But the remaining files I get as Texture2D??

According to the online manual Texture2D has a GetRawTextureData that should give me the byte array - but sadly this method is NOT available in Unity 4.6.7 and gives me a compile error if I try to use it. http://docs.unity3d.com/ScriptReference/Texture2D.GetRawTextureData.html

I don't ever want my files back as Texture2D - is there a way to force Resources.Load to give me a TextAsset?

Is there a backwards compatible way of getting the byte data for a Texture2D?

I only need the byte[] with the file contents - so other ways of doing just that for a Resource is most welcome.

Comment
Add comment · Show 2
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 troien · Aug 10, 2015 at 12:57 PM 0
Share

Showing the actual code you use for this could be helpful. (depending on the size perhaps also the file in question, so that people can debug it themself).

I would say using something like this might work.

 Resources.Load<TextAsset>("path");

Or this, which does besically the same but you'll still need to manually cast it to TextAsset:

 Resources.Load("path", typeof(TextAsset));

Although I'm not sure what Unity does internally, so both might also return null when Unity can't cast the file which he thinks is a Texture2D to a TextAsset...

avatar image frjtrifork · Aug 10, 2015 at 01:03 PM 0
Share

Thank you @troien - Both your suggestions work - I was pretty sure that I had tried tried your first suggestion (and was unaware of the syntax for the 2nd suggestion) - but that may have been before I realized that I had to alter the file extension to .bytes for TextAsset to support it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by TheFastLane · Mar 01, 2021 at 03:31 PM

I have had similar situations where I have a non standard asset that I want to load from resources and save to the devices folder structure at runtime. The comments on @frjtrifork 's question worked perfectly. To summarize:

  1. Rename your asset's file extension to ".bytes" (If you're in Windows you may have to enable viewing file extensions)

  2. Place your newly renamed asset in the Resources folder in your Unity project

  3. Run "TextAsset asset = Resources.Load("asset/file/path");"

  4. Then "File.WriteAllBytes("device/file/path.originalExtension", asset.bytes);"

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 amiel_ace · May 20, 2021 at 02:19 PM 1
Share

thanks dude

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Hiding Texture2D after a sec 1 Answer

What's the most effecient way to rotate a texture? 1 Answer

Scaling / Resizing an Image (Texture2D) 6 Answers

GUI.Label or any text with GUIStyle as Texture 1 Answer

Trying to display a screen capture as a loading screen. 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