- Home /
UI and WebCamTexture problems when Android lock screen is shown
Hey there,
I've already asked a question about how to get the android lock screen enabled in dev builds because I need to debug an issue which only occurs when the lock screen is shown. However I thought I ask if anyone knows how to just solve the problems I'm having.
I'm almost certain it has something to do with the WebCamTexture as, in most parts of my app, I can lock then unlock the device just fine. In the one part which uses a WebCamTexture to show the feed from the device's camera on screen, things go wrong.
What tends to happen is that once I unlock, the app resumes but some of my UI elements are missing. Specifically the RawImage displaying the WebCamTexture is missing as are any UI elements in the same level of the Unity Editor's hierarchy or lower. UI elements higher up the hierarchy are present and correct. In my case this means before I lock the device I can see this;
An exit button in the top left, my WebCamTexture center, and two buttons along the bottom. However after I unlock the screen I see this;
All the UI bar the exit button is missing. Sometimes the app continues to work though all I can do his hit the exit button. Sometimes it crashes shortly after. I've tried my best to work around the problem by disabling the WebCamTexture when the lock occurs and so on but so far I've had no luck.
Any advice would be gratefully received.
Right, no sooner do I post this than I find a solution.
I just changed how I'm stopping the WebCamTexture when the device locks and now it's working. Still this feels like a pretty work around and that I could be missing something, so I'll leave the question open in case anyone has a better solution. For anyone who is interested I've solved it by doing this.
void OnDisable()
{
$$anonymous$$illWebcam();
}
void OnApplicationPause(bool paused)
{
if (paused)
{
$$anonymous$$illWebcam();
}
}
void OnApplicationFocus(bool focused)
{
if (!focused)
{
$$anonymous$$illWebcam();
}
}
private void $$anonymous$$illWebcam()
{
if (m_webcamTexture != null)
{
m_cameraImage.texture = null;
m_webcamTexture.Stop();
m_webcamTexture = null;
}
}
Though obviously that needs to be coupled with code which sets the webcam up again when the device unlocks.
Your answer
Follow this Question
Related Questions
WebCamTexture crashes on android 0 Answers
Input field crashes on Android 4.1.2 (Unity 5.1.1f1) 0 Answers
How do I enable the Android lock screen in developer mode? 1 Answer
Random crashes in Android build 0 Answers
WebCamTexture and Nexus 6p 0 Answers