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 Julien-Lynge · Feb 17, 2014 at 03:54 AM · webplayertexture2dcreate a texture

Fastest way to load a Texture2D in Unity (web player)?

I'm trying to figure out the fastest way to create or update a Texture2D in Unity.

The fastest way by far is to use unmanaged code - a native plugin - that directly overwrites the texture in memory without going through Unity. Unfortunately, we can't use unmanaged code in the Unity web player, so I'm trying to determine just how fast we can load a texture using the methods Unity has offered us.

The reason for this is that Unity loads new textures on its main thread. This means that the entire Unity application waits while a texture is being created or loaded, and if you try to load a large texture (say 4096x4096) it will actually noticeably freeze the application while this is going on. Definitely not a good thing.

We played around with the basic ways of creating/updating textures a while back. Both SetPixels32 and LoadImage are just too slow, no matter what tweaks we tried.

Recently, we tried loading raw data through Texture2D.LoadRawTextureData and passing ARGB data. For 4096x2048 it was taking 20 ms - too slow. The time seemed to be linear - a 2048x2048 image took 10 ms, and loading just RGB took 15ms. We can also try directly loading DXT data - perhaps it too will linearly scale, and the 4x reduction will make it fast enough. Of course, compression doesn't work for every use case.

Does anyone else know a faster way of creating/loading to a texture in Unity, within the restrictions of the web player?

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 Klarax · Feb 17, 2014 at 09:49 AM 1
Share

Im no expert, but have you tried loading it into the scene, on an object off cam at start of game, and then when you need to use it it will already be there in memory?

Only way i can think of doing it, otherwise, like you said, it will pause...

avatar image Julien-Lynge · Feb 18, 2014 at 01:19 AM 0
Share

Hey @$$anonymous$$larax,

Your solution would certainly work in a lot of cases. A similar one would be to include your texture in an asset bundle, though I'm not sure if there's any delay in loading textures from bundles.

Unfortunately, in our case we don't know beforehand what textures we'll need for a given user. We're actually working on a data visualization project using Unity, which is a bit of a different use case from many users.

Thanks for the idea!

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

issue with create texture2d in background Task, probably a bug ? 0 Answers

Can I create a sprite at runtime? 3 Answers

How to show image on Camera View programmatically in Unity3d 1 Answer

How does setting the hideFlags resolve leaking issues? (Texture 2D leaking) 2 Answers

rotate an image by modifying Texture2D.GetPixels32() array 2 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