Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by davidopix · May 03, 2019 at 12:55 PM · imageloadingstreamingassets

Loading external images without stutter

Hi,

For our project we need to load images from streaming assets or a webservice. We can't load them as ressources because images can change, and there is about 100.000 images. We don't need to load them all, but we need to load a bunch of images while an other previously loaded bunch of images are moving.

How can i do this without freezing the app? : When i load images, the moving ones seems to stutter

I tried sevaral things, like coroutines or tasks, but unfortunnaly nothing works, always stuttering. Does anybody knows how to accomplish that? Is there a way to load external images on a different thread?

Thank you for your help,Hi,

For our project we need to load images from streamingassets or a webservice. We can't load them as ressources because images can change, and there is about 100.000 images.

We need to load images while other images are moving (others loaded previously).

How can i do this without freezing the app? : When i load images, the moving ones seems to stutter

I try sevaral things, like coroutines or tasks, but unfortunnaly nothing works. Does anybody knows how to accomplish that? Is there a way to load external images on a different thread?

Thank you for your help

Comment
Add comment · Show 1
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 thomh_unity · May 20, 2019 at 08:05 AM 0
Share

Hi,

Can you show a little of how you're currently doing this?
At what point is the stutter happening?

Best regards,
Thom.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by davidopix · May 20, 2019 at 08:47 AM

Hi, Certainly @thomh_unity ! : First, this is a try to see how Unity manage loading external file for my project. I use UI raw images, to avoid use of sprite creation. So, i use a scene with:

  • A red square with a looping animation going from left to right and back

  • 10 raw images.

Each raw image has a ImageTextureLoader.cs (joint file ImageTextureLoader.txt), loading behavior with coroutine using UnityWebRequestTexture. In my main cs, i load each texture one after the other. Pictures are jpg, from 4.8 Mo to 8.9 Mo

The stutter occurs on loading file, or while affecting texture to raw image, i don't know precisely. But i can see the stuttering on the animated red square.

Best regards David link text


imagetextureloader.txt (1.5 kB)
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 thomh_unity · May 20, 2019 at 09:18 AM 0
Share

Hi @davidopix,

There could be many reasons you're seeing this kind of issue.

$$anonymous$$nowing precisely where the stutter occurs will help to understand the problem.

Can you please provide some of the code you're using in the co-routine?

Thanks,
Thom.

avatar image davidopix thomh_unity · May 20, 2019 at 09:23 AM 0
Share

Hi, this is the code used in ImageTextureLoader.cs :

using System; using System.Linq; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; using System.Collections; using CielaSpike;

public class ImageTextureLoader : $$anonymous$$onoBehaviour {

 public event Action OnComplete;

 public string url;

 protected string _loadUrl;
 protected RawImage _image;
 protected Texture2D _tex;
 protected float _texWidth;
 protected float _texHeight;
 protected Sprite _sprite;

 protected bool _loaded = false;

 private void Start()
 {
     _image = GetComponent<RawImage>();
 }

 public void Load()
 {
     _tex = new Texture2D(4096, 4096);
     _loadUrl = "file:///" + Application.strea$$anonymous$$gAssetsPath + "/" + url;

     StartCoroutine(LoadTexture());
 }

 IEnumerator LoadTexture()
 {

     UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(_loadUrl);

     yield return new WaitForEndOfFrame();

     yield return uwr.SendWebRequest();
     yield return new WaitForEndOfFrame();

     if (uwr.isNetworkError || uwr.isHttpError)
     {
         Debug.Log(uwr.error);
     }
     else
     {
         yield return new WaitForEndOfFrame();

         _tex = ((DownloadHandlerTexture)uwr.downloadHandler).texture;

         yield return new WaitForEndOfFrame();

         uwr.Dispose();

         yield return new WaitForEndOfFrame();

         _loaded = true;
     }
 }

 void LateUpdate()
 {
     if (!_loaded) return;
     _loaded = false;
     _image.texture = _tex;
     if (OnComplete != null) OnComplete();
 }

}

avatar image thomh_unity davidopix · May 20, 2019 at 10:14 AM 0
Share

Hi,

Am I understanding correctly that you have one of these scripts for each image you are trying to load? This will mean each image is trying to load at the same time.

Have you tried loading the images one at a time?

Thanks,
Thom.

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

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

Related Questions

Download images and apply to sprite 0 Answers

Unity can not access StreamingAssets on IOS 1 Answer

Wrong JPEG library version 0 Answers

Dynamic load of Image target - ARKit 0 Answers

Make several buttons out of a single image (basic question) 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