When making scene transitions my WebcamTexture doesn’t get properly destroyed. During the next scene, creating a new WebcamTexture incorrectly initializes the device parameters and never updates frames. Also after Stopping playmode, my camera stays on (with the light on), and the only way to free it is to close the unity editor.
This is a minimum example, where I can reproduce this issue. Just use this component on a scene object and press enter to switch scenes.
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CamTest : MonoBehaviour {
WebCamTexture liveFeed;
IEnumerator Start ()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
liveFeed = new WebCamTexture();
liveFeed.Play();
}
else
Debug.LogWarning("Camera access not obtained!");
}
void OnDisable ()
{
if (liveFeed && liveFeed.isPlaying)
liveFeed.Stop();
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Return))
{
SceneManager.LoadScene(gameObject.scene.name);
}
}
}