Author Topic: Unity 5.1, WebCamTexture not working with UITexture on Android  (Read 5700 times)

Meltdown

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 56
    • View Profile
I'm using a WebCamTexture which updates the UITexture with whatever is seen by the device camera.

If I use a standard Unity plane and renderer as my texture, the texture is updated and shows what the camera is viewing, in both the editor and on my Android device.

However, if I use a UITexture, although the camera works in the editor and shows on the UITexture, it doesn't work on my Android device, there is just a black texture.

This is my script...
I am using NGUI 3.9.0

  1. public class WebcamTest : MonoBehaviour {
  2.         public string deviceName;
  3.         WebCamTexture wct;
  4.  
  5.         [SerializeField] UITexture _uiTexture;
  6.  
  7.         // Use this for initialization
  8.         void Start () {
  9.                 WebCamDevice[] devices = WebCamTexture.devices;
  10.                 deviceName = devices[0].name;
  11.                 wct = new WebCamTexture(deviceName, 400, 300, 12);
  12.                 //GetComponent<Renderer>().material.mainTexture = wct;
  13.                 //_uiTexture.material.mainTexture = wct;
  14.                 _uiTexture.mainTexture = wct;
  15.                 wct.Play();
  16.         }
  17. }
  18.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 5.1, WebCamTexture not working with UITexture on Android
« Reply #1 on: June 18, 2015, 07:53:32 AM »
Black texture means the texture format / size is not supported on your device. Many mobile devices need power-of-two texture sizes while yours isn't (400x300). Not sure why the plain texture works while UITexture doesn't in your case.