I’m trying to render a image/png texture from a url onto a newly instantiated cube. It works great when I am testing in the Unity Editor, but the second I move over to the Hololens the texture is not rendering as I simply see the bright pink default texture.
I’ve tried all the advice from the below linked discussion, but still no dice. InternetClient and InternetClientServer are enabled and I’ve tested the URL in the Hololens browser and it worked fine.
Am I missing an option in Package.appxmanifest or is this a known bug in the Hololens?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class ForumSample : MonoBehaviour
{
void Start ()
{
StartCoroutine (retrieveImageAndAttachToGameObject ());
}
IEnumerator retrieveImageAndAttachToGameObject ()
{
UnityWebRequest www = UnityWebRequest.GetTexture ("<url_to_png_image>", false);
www.SetRequestHeader ("Accept", "image/png");
Debug.LogError ("Downloading...");
yield return www.Send ();
while (!www.isDone) {
Debug.LogError (".");
yield return null;
}
if (www.isError) {
Debug.Log (www.error);
} else {
Debug.Log ("Getting the texture content");
// Instantiate a cube
GameObject go = GameObject.CreatePrimitive (PrimitiveType.Cube);
// Attach the browser image to the instantiated cube
go.GetComponent<Renderer> ().materials [0].mainTexture = DownloadHandlerTexture.GetContent (www);
}
}
}