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 CyberMew · Sep 04, 2013 at 08:59 AM · texture2ddynamicpcimages

Loading texture resource runtime?

I know we can use script to load an image for example, but they have to be stored in the Resources folder. However, if I build the game into an exe, those file resources are no longer accessible. Then, I could no longer "modify the images" without building the game again via Unity. How can I workaround that?

edit: To clarify, if the game reads from an XML and decides which image to load (say I want to change/add a new portrait for a character, or even allow modders to change it when the game is released), I can neither change the image itself, or add new images (with different file names). These images has to be hardcoded before we build the exe, and no longer being data-driven.

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
Best Answer

Answer by Tarlius · Sep 04, 2013 at 09:03 AM

You can use AssetBundles, or use Texture2D.LoadImage() to load a png or jpeg.

If you want to do something more clever, you can also create empty textures and pass the NativeTextureID rebuild them in native code.

Comment
Add comment · Show 6 · 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 CyberMew · Sep 04, 2013 at 06:05 PM 0
Share

I am using the Indie/Free version of Unity, forgot to mention that!

I took a look at the LoadImage function, correct me if I am wrong, but apparently it uses TextAsset which uses the Resources folder as well :(

Looks like there is no easy way out for us!

avatar image Tarlius · Sep 05, 2013 at 01:51 AM 0
Share

"This function loads a JPG or PNG image from raw byte[] array."

You can use standard c# file loading methods to get the byte array. For example, File.ReadAllBytes

avatar image CyberMew · Sep 05, 2013 at 05:10 AM 0
Share

Wow thanks a lot, I didn't know about that function (came from C). This should really be in the documentation as an example!

avatar image Tarlius · Sep 05, 2013 at 05:17 AM 0
Share

I'll admit that an example that relies on a text asset isn't the most intuitive example... Like you say, if you have an image as a text asset you could have just imported it as an image, after all.

Watch out for this kind of thing in other places too. There is usually an option for reading directly from a byte array/stream for most things (to cover use cases like yours).

avatar image CyberMew · Sep 05, 2013 at 04:56 PM 0
Share

Indeed. Thanks for the heads up!

By any chance, do you know how can we remove the nearest power of 2 property that Unity impose on the texture while my singleton is calling LoadImage?

Show more comments

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

17 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 avatar image avatar image avatar image avatar image

Related Questions

What is the best way to draw a 2D sine wave? 3 Answers

How to generate 12 bit grayscale image 0 Answers

add text to a Texture2D while game is running 2 Answers

My Dynamic texture not showing up in the Build??? 0 Answers

Loading multiple images using only 1 www call? 0 Answers


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