I'm trying to download and use image from my Firebase storage using this example:
How to download image from firebase database, and load it into image in unity
Follow Debug find a problem:
UnityEngine.UnityException: SupportsTextureFormatNative can only be called from the main thread.
Can you offer please, how to solve it? Or maybe you can offer different way to download and use image.
Thanks!
My code:
var firebase = FirebaseStorage.DefaultInstance;
var storageRef = firebase.GetReferenceFromUrl(_urlPics);
storageRef.Child(_resourceName).GetBytesAsync(1024*1024).ContinueWith(task =>
{
if (task.IsCompleted)
{
var texture = new Texture2D(2, 2);
byte[] fileContent = task.Result;
texture.LoadImage(fileContent);
var newRect = new Rect(0.0f, 0.0f, texture.width, texture.height);
var sprite = Sprite.Create(texture, newRect, Vector2.zero);
_image.sprite = sprite;
Debug.Log("FINISH DOWNLOAD");
}
else
{
print("DOWNLOAD WRONG");
}
});
Error throw from:
var texture = new Texture2D(2, 2);