Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using OBS Studio as webcam

Discussion in 'Editor & General Support' started by eco_bach, May 25, 2020.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    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

    Code (CSharp):
    1.  using UnityEngine;
    2. using System.Collections;
    3. public class WebcamTest : MonoBehaviour {
    4.    public string deviceName;
    5.  
    6.     public Renderer webCamCanvas;
    7.    WebCamTexture _wct;
    8.      WebCamDevice[] _devices;
    9.  
    10.  
    11.    // Use this for initialization
    12.    void Start () {
    13.       _devices = WebCamTexture.devices;
    14.  
    15.      //deviceName = _devices[0].name;
    16.      _wct = new WebCamTexture("OBS-Camera", 400, 300, 12);
    17.  
    18.  
    19.      webCamCanvas.material.mainTexture = _wct;
    20.    
    21.  
    22.        // CheckDeviceNames();
    23.         _wct.Play();
    24.          if (_devices.Length > 0)
    25.          {
    26.             Debug.Log("Number webcams is "+_devices.Length);
    27.              foreach (WebCamDevice wcd in _devices)
    28.              {
    29.                  Debug.Log(wcd.name);
    30.               }
    31.          }
    32.    }
    33.  
    34.  
    35.  
    36.    // For photo varibles
    37.  
    38.    public Texture2D heightmap;
    39.    public Vector3 size = new Vector3(100, 10, 100);
    40.  
    41.  
    42.    void OnGUI() {    
    43.      if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
    44.        TakeSnapshot();
    45.    
    46.    }
    47.  
    48.    // For saving to the _savepath
    49.    private string _SavePath = "C:/WebcamSnaps/"; //Change the path here!
    50.    int _CaptureCounter = 0;
    51.    void TakeSnapshot()
    52.      {
    53.        Texture2D snap = new Texture2D(_wct.width, _wct.height);
    54.        snap.SetPixels(_wct.GetPixels());
    55.        snap.Apply();
    56.        System.IO.File.WriteAllBytes(_SavePath + _CaptureCounter.ToString() + ".png", snap.EncodeToPNG());
    57.        ++_CaptureCounter;
    58.    }
    59. }
     
  2. LinnL

    LinnL

    Joined:
    Sep 30, 2020
    Posts:
    5
    Hi, I have encountered the same problem. Did you found the solution? Please let me know if you have found out :)
     
  3. kirbyderby2000

    kirbyderby2000

    Joined:
    Apr 28, 2017
    Posts:
    35
    ckriger and LinnL like this.
  4. Jet4Games

    Jet4Games

    Joined:
    Nov 18, 2018
    Posts:
    2
    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?
     
  5. sonnyb

    sonnyb

    Joined:
    Nov 5, 2013
    Posts:
    16
    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:

    ERROR - Could not find specified video device


    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)"​
     
    mrtenda, ruby40482, kzkyuta and 2 others like this.
  6. antti_partagames

    antti_partagames

    Joined:
    Nov 5, 2015
    Posts:
    18
    sonnyb and system-idle like this.
  7. antti_partagames

    antti_partagames

    Joined:
    Nov 5, 2015
    Posts:
    18
    Serg1785, ItalicSeal and sonnyb like this.