WebCam texture doesn't work on Build Windows - Unity 2022.1.17f1

WebCamTexture works fine on editor, but doesn’t work on Build. I have tried: turn off antivirus and firewall, check authorization, put the webcamtexture on UI_RawImage and a plane gameObject, nothing works on build. There is no any real conclusion about the same bug on the forums (many are about Vuforia, and I just want to take a photo by a simple webcam on Windows). Any clues? Below the code. Tks in advance.

using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
using System.Collections.Generic;


public class GetCam2 : MonoBehaviour
    WebCamTexture webCam;    
    //string your_path = "D:\\Lixo\\FotosCam";// any path you want to save your image 
    [SerializeField] string your_path = "";
    public RawImage display;
    public AspectRatioFitter fit;
    public int contadorFotos;
    [SerializeField] GameObject planoWeb;

    IEnumerator Start()
        your_path = "" + Application.dataPath;

        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
        if (Application.HasUserAuthorization(UserAuthorization.WebCam)) {


    void LigaCamComeco1() {
        if (WebCamTexture.devices.Length == 0)
            Debug.LogError("can not found any camera!");
        int index = -1;
        for (int i = 0; i < WebCamTexture.devices.Length; i++)
            if (WebCamTexture.devices*.name.ToLower().Contains("pc"))*

Debug.Log(“WebCam Name:” + WebCamTexture.devices*.name + " Webcam Index:" + i);*
index = i;

if (index == -1)
Debug.LogError(“can not found your camera name!”);

WebCamDevice device = WebCamTexture.devices[index];
webCam = new WebCamTexture(;
display.texture = webCam;
planoWeb.GetComponent().materials[0].mainTexture = webCam;

public void Update()
if (Input.GetKeyDown(KeyCode.PageUp)) {

void Ratio() {
float ratio = (float)webCam.width / (float)webCam.height;
fit.aspectRatio = ratio;

float ScaleY = webCam.videoVerticallyMirrored ? -1f : 1f;
display.rectTransform.localScale = new Vector3(1f, ScaleY, 1f);

int orient = -webCam.videoRotationAngle;
display.rectTransform.localEulerAngles = new Vector3(0, 0, orient);

public void callTakePhoto() // call this function in button click event
IEnumerator TakePhoto() // Start this Coroutine on some button click
yield return new WaitForEndOfFrame();

Texture2D photo = new Texture2D(webCam.width, webCam.height);

byte[] bytes = photo.EncodeToJPG();
File.WriteAllBytes(your_path + “\ZaxisCam” + contadorFotos + “.jpg”, bytes);


Sorry, the problem has nothing about Unity. I just had to change ESET configuration, turn off webcam protection

Hello, I have the same problem, my webcam is all black. Try updating unity. I tried to run it on Windows 10 thinking it was a camera permissions problem. Try setting it to super low quality. I thought it was the opencv library. Tomorrow I will try to deactivate Kasperky. Please some extra solution.