- Home /
Cam texture stopped working in Unity 5/Android Lollipop
Hello guys. I'd like to start by saying that i updated almost simoultaneously to unity 5 and my Moto g 2013 to android 5.0.2 so I don't know the exact source of the issue.
Basically i'm remastering my android game to unity 5 and I'm getting some real issues that are getting me mad with a webcamtexture (i use it to scan some qr).
Before this upgrade it worked just fine: i have a script attached to a mesh renderer that shows me what the camera is pointing to like all the applications that uses camera and i could just use it to get all the informations i wanted. But now it suddenly stopped working and i have 0 clue about what the cause could be.
The mesh that used to show the camera results now is just a plain purple quad for the whole time and i keep getting errors like this in the logcat:
I/Unity (14652): NullReferenceException: Object reference not set to an instance of an object
I/Unity (14652): at ScanTest.OnDestroy () [0x00000] in <filename unknown>:0
I/Unity (14652):
I/Unity (14652): (Filename: Line: -1)
I/Unity (14652):
Love you logcat for being so clear and pointing me to immaginary negative lines of code
And this is the simple script i use (without the qr scanning stuff for making it cleaner but trust me I triple checked and (unfortunately) it doesn't work):
using UnityEngine;
using System.Collections;
public class ScanTest : MonoBehaviour
{
private WebCamTexture camTexture;
void Start ()
{
camTexture = new WebCamTexture();
camTexture.requestedHeight = Screen.height; // 480;
camTexture.requestedWidth = Screen.width; //640;
camTexture.Play();
}
void Update () {
camTexture.GetPixels32();
GetComponent<MeshRenderer>().material.mainTexture = camTexture;
}
void OnDisable()
{
if (camTexture != null)
{
camTexture.Pause();
}
}
void OnDestroy()
{
camTexture.Stop();
print("the camTexture is not null");
}
}
After 4 hours of trying without result this makes me so angry! The game is out in the play store. If someone can help me he will get a special thanks in the release notes.
Many thanks and regards.
Two months later... any progress? Can you simply not call camTexture.Stop()?
It came out that there were a bug on Unity 5 corrected in a patch that after converting the project into unity 5 it removed the mesh component from the gameObject that had to show the camera feedback. Removing the component and adding it again solved the issue.