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;
}
}