Live webcam stream in unity

So, I’ve been trying to make a webcam stream where the server sends a live stream from his webcam to the clients on the network. I’ve tried to write a code myself (I’m not very good at it), but for some reason it doesn’t work. Here it is:

#pragma strict

var webcamTexture : WebCamTexture;
var data : Color32[];


function OnServerInitialized() {
    	webcamTexture = WebCamTexture();
   		renderer.material.mainTexture = webcamTexture;  
   		webcamTexture.Play();
    	data = new Color32[webcamTexture.width * webcamTexture.height];
}

function Update () {
    webcamTexture.GetPixels32 (data);
}

function OnConnectedToServer() {
   	networkView.RPC ("WebcamStream", RPCMode.Others, data, webcamTexture);
    webcamTexture.Play();
}

@RPC
function WebcamStream (data : Color32 [], webcamTexture: WebCamTexture) {
	var	newwebcamTexture: WebCamTexture = webcamTexture;
	renderer.material.mainTexture = newwebcamTexture;
 	var newdata: Color32[] = data;
    webcamTexture.GetPixels32 (newdata);
}

It just results in a blank screen on the client’s side. Any help will be much appreciated :slight_smile:

If someone still needs examples, you may try FMETP STREAM | Forum

It provides Streaming Demo with UDP/TCP/WebSocket solution, and Web browser demo with Socket.IO.

All source code are written in C# and easy to modify.

Supported: Android/iOS/Mac/PC/AR/VR/Linux/HoloLens/OculusGO/MagicLeap/WebGL/HTML…etc

Hello,

he problem in your program is that you have used invalid arguments for RPC

Valid RPC parameters are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion.

so you cannot pass anything else other than the above in RPC…

In this case you have to use OnSerializeNetworkView for transferring data. And you cannot transfer webcam texture straight away, you have to use GetPixel32 in webcamtexture class. and get the array, use serialize on the array and it would be sent to the other system (This part will be more clear if u check the example in OnSerializeNetworkview page)