Unity3D webcam rendering: incorrect rotation and flip using WebCamTexture

04 Nov

When rendering webcam as textures, Unity3D ships with a useful WebCamTexture class, the typical use of this class is as follows:

  • Create a GUITexture object: in unity menu:  GameObject  arrow, dash, right icon  Create Other  arrow, dash, right icon  GUI Texture, let’s name it CamTexture;
  • Create a C# script, let’s also name it CamTexture.cs
  • In the script, create an instance of WebCamTexture:

    WebCamTexture webcamTexture;

  • In the Start() function, add below code:

    webcamTexture = new WebCamTexture();               
    guiTexture.texture = webcamTexture;       

Wrongly oriented CAM View

Actual physical view

  • Drag CamTexture.cs to the CamTexture game object in Unity3d; build and run the app in your android device;
  • When you run the application, you will see very small camera view shown in your device, this is because when you create the CamTexture game object, you did not set the Pixel Inset values and default values are used instead:


  • Let’s make the GUI texture to be rendered in full screen mode, in the Start() function, add below code lines to the top of the function body:

    float W = Screen.width;
    float H = Screen.height;
    float InsetX = -( W / 2) ;
    float InsetY = -( H / 2) ;
    guiTexture.pixelInset = new Rect(InsetX, InsetY, W, H);

Build and re-run the app, you will find that webcam is rendered in full screen, but the textures seem to be rendered with 90 degree rotations and possibly some flips:

To solve this, you can change the Player Settings during the app build process
–> Press Ctrl + Shift + B or click menu File  arrow, dash, right icon  Build Settings… ,
–> Click the “Player Settings…” button, and Unity3D inspector shows a panel, as shown below.
–> Choose whichever settings under “Resolution and Presentation” category, e.g. “LandScape Left”
–> Rebuild and run the app. Oh yeah, yeah… it worked now!

unity_webcam_a image

It was noted by many other posts that, if this does not work, you can add below line on a trial and error basis:

guiTexture.transform.localScale = new Vector3(-1,-1,1);     

The entire code looks as below. Happy coding and enjoy!


CamTexture.cs (Remember to associate it with a GUI Texture game object).
Unity Cam Texture Project


Posted by on November 4, 2013 in Programming, Unity 3d


Tags: , , , , , , , , , ,

3 responses to “Unity3D webcam rendering: incorrect rotation and flip using WebCamTexture

  1. OOIII

    September 15, 2014 at 7:11 pm

    if i render the webcam with “drawtexture” directly,how can i fix the problem.?ths for your answer.

  2. Narjes

    May 17, 2015 at 8:34 pm

    I have the same exact problem with unity 3D on android about camera and i followed the same instruction …Well, the problem of the camera has been fixed but my augmented reality does’nt work anymore .i.e: the cube for exemple that must appear on my AR marker does’nt appear anymore .. as i have only the camera that works without any thing else ….Please can any body help me . Thank you in advance .

    Ps: I am working with unity 3D version 4.5.0 pro and NyAR toolkit for an augmented reality application.

  3. Narjes

    May 19, 2015 at 3:34 am

    Hi ! i am making an augmented reality application with unity 3D and NYartoolkit and have the same problem of bad rotation camera when i build on android so i followed the same instructions. The problem of the camera has been fixed But my application does’nt work any more. for exemple a cube should appear on my Artoolkit marker when playing the game but nothing appears or works without giving me any error. It’s like i have only the camera that works with the full screen mode on my andoid device without any other application. Is there any other thing i should add or fix in unity !!??


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: