Using OBS Studio as webcam

So whats the trick to getting OBS studio working as webcam?

I installed the VirtualCam plugin for OBS Studio.

When I run OBS Studio I can see the webcam preview.
I open the “VirtualCam” plugin popup inside OBS studio and click Start.

I am using “OBS-Camera” as my Device name inside Unity .

But the webcam does NOT render inside Unity.
If instead I simply used “Integrated Webcam” as my device name i correctly see the built in webcam being rendered.

complete code

 using UnityEngine;
using System.Collections;
public class WebcamTest : MonoBehaviour {
   public string deviceName;

    public Renderer webCamCanvas;
   WebCamTexture _wct;
     WebCamDevice[] _devices;

 
   // Use this for initialization
   void Start () {
      _devices = WebCamTexture.devices;

     //deviceName = _devices[0].name;
     _wct = new WebCamTexture("OBS-Camera", 400, 300, 12);


     webCamCanvas.material.mainTexture = _wct;
   

       // CheckDeviceNames();
        _wct.Play();
         if (_devices.Length > 0)
         {
            Debug.Log("Number webcams is "+_devices.Length);
             foreach (WebCamDevice wcd in _devices)
             {
                 Debug.Log(wcd.name);
              }
         }
   }


 
   // For photo varibles
 
   public Texture2D heightmap;
   public Vector3 size = new Vector3(100, 10, 100);
 
 
   void OnGUI() {    
     if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
       TakeSnapshot();
   
   }
 
   // For saving to the _savepath
   private string _SavePath = "C:/WebcamSnaps/"; //Change the path here!
   int _CaptureCounter = 0;
   void TakeSnapshot()
     {
       Texture2D snap = new Texture2D(_wct.width, _wct.height);
       snap.SetPixels(_wct.GetPixels());
       snap.Apply();
       System.IO.File.WriteAllBytes(_SavePath + _CaptureCounter.ToString() + ".png", snap.EncodeToPNG());
       ++_CaptureCounter;
   }
}

Hi, I have encountered the same problem. Did you found the solution? Please let me know if you have found out :slight_smile:

You have to register a “dummy” camera into the Windows registry, otherwise you’ll just get black screens. There is a “reg_path.reg” registry file in the GitHub page of the Virtual Camera: Release OBS-VirtualCam 1.2.1 · CatxFish/obs-virtual-cam · GitHub

There was also a thread on Reddit about it here: Reddit - Dive into anything

2 Likes

Hey, Kirbyderby2000 I am also trying to use obs virtual camera. I have installed and ran reg_path but no luck. Any ideas how I (or anyone) else can get around this?

Problem

Using OBS 27, I had OBS virtual camera working in Google Chrome but not in Unity 2020.3.

UnityEngine.WebCamTexture was throwing this error:

Using the OBS-Virtual-Camera reg_path.reg key did not solve the issue.

(I’m not sure why I started having this error, because it worked fine for me without this registry key a few months ago / last year… it might be related to upgrading OBS or maybe something changed on my PC.)

Workaround solution

I reverted to an older version (to a version before the virtual camera was a built-in OBS feature) and installed:

From this OBS Virtualcam 2.0.5 plugin overview page, note this known issue:

“Unity can’t get image from virtualcam, please use register batch (reg_path.reg) in release page to manually add dummy device path .(note: The registry conflict with skype desktop , you can use unreg_path.reg to remove it)”

5 Likes

Not being able to use OBS virtual camera directly with the WebCamTexture is a reproducible bug in Unity. I submitted a report so hopefully it will be fixed at some point. In the meantime, please vote for the issue here

2 Likes

This is now fixed since 2021.3.14f1, 2022.1.23f1, 2022.2.0b15, 2023.1.0a14

3 Likes