Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[HELP]big problem with Image2DLoadFromFile

Discussion in 'Project Tiny' started by wbq9224, Sep 6, 2019.

  1. wbq9224

    wbq9224

    Joined:
    Sep 4, 2019
    Posts:
    3
    I want to load images with url and creat a new sprite for sprite renderer. I use code like this:

    Code (JavaScript):
    1.             let texture2D = this.world.createEntity();
    2.        
    3.             this.world.setEntityName(texture2D , name + "_texture2D");
    4.             this.world.addComponent(texture2D , ut.Core2D.Image2DLoadFromFile);
    5.             this.world.usingComponentData(texture2D , [ut.Core2D.Image2DLoadFromFile] , (file)=>{
    6.                 file.imageFile = localStorage.getItem("saved-image-example");
    7.                
    8.             });
    9.  
    10.             // Load Texture Entity
    11.             this.world.addComponent(texture2D , ut.Core2D.Image2D);
    12.             this.world.usingComponentData(texture2D , [ut.Core2D.Image2D] , (image)=>{
    13.                 Image.pixelsToWorldUnits = 0.01;
    14.             });          
    15.    
    16.             // Create Sprite Entity
    17.             let sprite2D = this.world.createEntity();
    18.             this.world.setEntityName(sprite2D , name + "_sprite2D");
    19.             this.world.addComponent(sprite2D , ut.Core2D.Sprite2D);
    20.             this.world.usingComponentData(sprite2D , [ut.Core2D.Sprite2D] , (sprite)=>{
    21.                 sprite.image = texture2D;
    22.                 sprite.imageRegion = new ut.Math.Rect(0, 0, 1, 1);            
    23.                 sprite.pivot = new Vector2(0.5, 0.5);
    24.             });
    It's work.
    But after I load the image multiple times, i got an error:
    upload_2019-9-6_14-8-49.png

    I tested each line of my code and I find when I add "Image2DLoadFromFile" i got this error.
    So I guess befor I load a new image with "Image2DLoadFromFile" I need to "release" or "empty" or "destroy" the old image. But how? Does anyone can help me? PLEASE.
     
unityunity