Question

I am building an application in Unity3d, and I need to download textures from my server and apply them to prefabs. I have two types of prefabs; The first is a simple plane that I use to display 2d images, and the second is a prefab to play videos and have a thumbnail texture that is displayed before the video is played in full screen.

I am having problems with the video prefab. If I create a public texture in my script and apply it to the prefab, everything works fine. However, if I download the texture from my server and apply it to the prefab it appears black. This only happens in iOS, in the Unity Player everything appears fine.

Here is my code:

Instantiate the prefab:

newVideo = (GameObject)Instantiate(arvideo, new Vector3(15*i, 0, 0), Quaternion.identity);
newVideo.GetComponent<VideoPlaybackBehaviour>().m_path = ((Assets)Data.Assets[i]).AssetContent; // SET THE URL FOR THE VIDEO

string url = ((Assets)Data.Assets[i]).AssetThumbnail;
StartCoroutine(DownloadImage(url, newVideo, ((Assets)Data.Assets[i]).AssetFilename, "VIDEO"));

newVideo.transform.rotation = Quaternion.Euler(0, -180, 0);

Download IEnumerator:

public IEnumerator DownloadImage(string url, GameObject tex, string filename, string type) 
{

    WWW www = new WWW(url);
    yield return www;

    /* EDIT: */
    if (!string.IsNullOrEmpty(www.error)){
    Debug.LogWarning("LOCAL FILE ERROR: "+www.error);
    } else if(www.texture == null) {
    Debug.LogWarning("LOCAL FILE ERROR: TEXTURE NULL");
    } else {
    /* EOF EDIT */
        tex.GetComponent<VideoPlaybackBehaviour>().KeyframeTexture = www.texture;
        Color color = tex.renderer.material.color;
        color.a = 1f;
        tex.renderer.material.color = color;
    }

}

No correct solution

OTHER TIPS

I struggled with same issue. And after several hours search, for my case i solved this problem with disabling "Metal write-only BackBuffer" in iOS player settings. I'm using unity 2020.1.8f1 and actually i have no any idea about why back buffer setting is causing black texture problem in iOS devices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top