Search Unity

StreammingAssets Images not displayed on iphone or simulator

Discussion in 'iOS and tvOS' started by Fergmart, Sep 12, 2021.

  1. Fergmart

    Fergmart

    Joined:
    Nov 14, 2019
    Posts:
    1
    Hello.
    I am making a game for ios with multiple images in folders inside StreammingAssets. I access those images with Application.streamingAssetsPath as shown in the code below.
    In Unity everything works fine and the images are displayed but in the Xcode simulator and on the iphone device the images appear blank and I don't know why.

    I'm not getting any error when debugging in xcode and I don't know what the problem may be.
    I tried adding /Raw/ to streamingAssetsPath with same result.
    Any help o guidance would be apreciated.

    Code (CSharp):
    1.  
    2.                 string imagePath = picture.getimagesPath().ElementAt(i) + ".png";
    3.                 string fullPath = Path.Combine(Application.streamingAssetsPath, imagePath);
    4.  
    5.                 byte[] pngBytes = System.IO.File.ReadAllBytes(fullPath);
    6.  
    7.                 Texture2D tex = new Texture2D(2, 2);
    8.                 tex.LoadImage(pngBytes);
    9.                
    10.  
    11.                 Sprite slotImage = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
    12.  
    13.  
    14.                 slot.GetComponent<Image>().sprite = slotImage;