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
2
Question by Clavus · Feb 20, 2015 at 03:18 PM · coroutinetexture2dmultithreading

Multi-threaded / non-blocking way of encoding images to Texture2D

I have a image loader in my Unity project that loads a few dozen large PNG / JPG images into the game and then encodes them to Texture2D by simply requesting the WWW.textureNonReadable. The problem is that my main game thread freezes during that last step (several hundred milliseconds per large image). This is very annoying so I'm either looking for a way to (A) do Texture2D creation in a coroutine somehow or (B) create the Texture2D in a separate thread (which seems to be impossible since the Unity API isn't thread-safe) (would it be possible to do the decoding/encoding without Unity API functions / libraries?) (alternatively, would it be possible to run a separate Unity instance that handles file loading / Texture2D encoding and transferring that data back to the main instance?).

Pointers, and preferably examples, will be very much appreciated. Been stuck on this problem for quite a while.

Comment
Add comment · Show 4
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 hexagonius · Feb 20, 2015 at 04:15 PM 0
Share

A quick look directed me to this thread, maybe it helps you to create async tasks:

http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html

avatar image Clavus · Feb 20, 2015 at 04:21 PM 0
Share

The problem is that it's a Unity API method that eats up all my processing time, not calculations of my own. So I can't offload it to a different thread. And it doesn't appear to have handles to work with coroutines either.

avatar image Jessespike · Feb 20, 2015 at 05:04 PM 0
Share

Ins$$anonymous$$d of encoding textures in real-time while the game is playing, you can substitute for a thumbnail and encode the larger version at a time when the player wouldn't notice the freeze, such as a loading screen.

Not the solution you asked for, but I don't there's an easy fix (or any) unless you rewrite Unity... $$anonymous$$aybe a clever plugin could accomplish this, but I have no idea.

avatar image Clavus · Feb 20, 2015 at 05:31 PM 0
Share

Sadly I can't really hide the loading, my application has an image browsing feature that has to be able to dynamically load images into the 3D environment.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LightBuzz · Aug 15, 2018 at 02:36 PM

For JPEG images, you could download our Super Fast JPEG plugin from the Asset Store: http://u3d.as/1fxN

The JPEG plugin is based on libjpeg and libjpeg-turbo.

It's faster than Unity's EncodeToJPG() and can also run in background threads.

Comment
Add comment · 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

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

Load skybox pics at startup w/o using all ram 1 Answer

Instantiating many objects during update lags 1 Answer

Call long running AI function without tying up game loop? 1 Answer

Is it possible to split Texture2D.LoadImage into multiple parts? 1 Answer

Render a list of objects into a Texture2D array 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