Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by KnightRiderGuy · Feb 25, 2015 at 06:04 PM · canvasguitextureui imagewebcamtexture

Getting A Web Cam to Play on UI Texture Image

Alloha! :)

I'm trying to figure out how to get a Web Cam to play on a UI image as I have WAY more control over layout, so far all I have been able to find is how to get a web cam to play on a plane.

Is there a way to get something like this onto a UI.Image that can be positioned onto a canvas?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image t-schulz · Mar 08, 2016 at 05:22 PM 0
Share

Can you tell me how to save this on Android and iOS?

Thank you

avatar image Fattie · Mar 18, 2016 at 04:49 PM 0
Share

NOTE as I mentioned below there seems to be a critical new asset on the assetstore ... https://www.assetstore.unity3d.com/en/#!/content/52154

avatar image Wappsy · May 09, 2019 at 03:39 PM 0
Share

It seems WebCamTexture can only detect physical webcams, but how to do you make it use virtual webcams?

I want to use OBS (https://obsproject.com/welcome) or any other "virtual camera" video stream, how can you select this?

4 Replies

· Add your reply
  • Sort: 
avatar image
30
Best Answer

Answer by Max-Bot · Feb 25, 2015 at 07:38 PM

It's easy my friend. Use RawImage instead of Image. Add Unlit/Texture material to material property of RawImage. And use this code to play WebCam video on it:

 public class PlayMovieTextureOnUI : MonoBehaviour 
 {
     public RawImage rawimage;
     void Start () 
     {
         WebCamTexture webcamTexture = new WebCamTexture();
         rawimage.texture = webcamTexture;
         rawimage.material.mainTexture = webcamTexture;
         webcamTexture.Play();
     }
 }

alt text



webcamui.png (115.1 kB)
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JPhilipp · Mar 18, 2016 at 04:00 PM 4
Share

And for those who miss the header:

 using UnityEngine.UI;
avatar image bsq · Sep 09, 2016 at 08:43 PM 1
Share

THAN$$anonymous$$ YOU SO $$anonymous$$UCH !!!! PERFECT SOLUTION !

avatar image Mutony · Nov 23, 2016 at 07:33 AM 0
Share

This solution above doesn't work for me... im not sure why, i get this error: Assets/Play$$anonymous$$ovieTextureOnUI.cs(4,37): error CS0246: The type or namespace name `$$anonymous$$onoBehaviour' could not be found. Are you missing a using directive or an assembly reference?

avatar image pinkscooter · Feb 24, 2017 at 02:34 AM 0
Share

Thank you so much! Saved me so much time!

avatar image HamFar · Jun 12, 2017 at 09:49 AM 0
Share

Hi all, Do you know if the issue with "WebCamTexture breaking Android device camera autofocus" is solved yet? I am working on a project that does not allow the use of stuff from the AssetStore. Android Auto focus stopped working properly after creating a WebCamTexture and I cannot seem to find a way to control the focus of an Android camera through Unity, so it seems the only way to resolve this is to write my own plugin in Java, which will set auto-focus and then call it from Unity? Is this really the only way?

Show more comments
avatar image
1

Answer by KnightRiderGuy · Dec 19, 2017 at 03:09 PM

Hi @Max-Bot Would you possible be able to help with getting more than one web cam to be accessed?

UPDATE: Never mind, I figured it out. I tweaked this code to also display a UI Text to display the current camera in use.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 using UnityEngine;
 
 public class IDwebCams : MonoBehaviour {
 
     public RawImage rawimage;
     WebCamTexture webCamTexture;
 
     public Text webCamDisplayText;
 
     void Start ()
     {
 
 
         WebCamDevice[] cam_devices = WebCamTexture.devices;
         // for debugging purposes, prints available devices to the console
         for (int i = 0; i < cam_devices.Length; i++) 
         {
             print ("Webcam available: " + cam_devices [i].name);
         }
 
     }
 
 
     //CAMERA 01 SELECT
     public void GoWebCam01()
     {
         WebCamDevice[] cam_devices = WebCamTexture.devices;
         // for debugging purposes, prints available devices to the console
         for (int i = 0; i < cam_devices.Length; i++) 
         {
             print ("Webcam available: " + cam_devices [i].name);
         }
 
         webCamTexture = new WebCamTexture(cam_devices[0].name, 480, 640, 30);
         rawimage.texture = webCamTexture;
         if(webCamTexture != null)
         {
             webCamTexture.Play();
             Debug.Log("Web Cam Connected : "+webCamTexture.deviceName + "\n");
         }    
         webCamDisplayText.text = "Camera Type: " + cam_devices [0].name.ToString();
     }
     //CAMERA 02 SELECT
     public void GoWebCam02()
     {
         WebCamDevice[] cam_devices = WebCamTexture.devices;
         // for debugging purposes, prints available devices to the console
         for (int i = 0; i < cam_devices.Length; i++) 
         {
             print ("Webcam available: " + cam_devices [i].name);
         }
 
         webCamTexture = new WebCamTexture(cam_devices[1].name, 480, 640, 30);
         rawimage.texture = webCamTexture;
         if(webCamTexture != null)
         {
             webCamTexture.Play();
             Debug.Log("Web Cam Connected : "+webCamTexture.deviceName + "\n");
         }
         webCamDisplayText.text = "Camera Type: " + cam_devices [1].name.ToString();
     }
 }
 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Dec 20, 2017 at 08:40 PM 0
Share

On an important note: I did notice on my $$anonymous$$ac I did not have to stop texture from playing, but on my PC going back and forth between the two different camera would only work the one time. the way around this was to make each button run a short coroutine where first the web cam textures stops playing, then waits for about half a second before loading the 2nd camera and playing the webcamtexture again. Doing this for each button on the PC allowed for transition back and forth between camera views. Tested in a stand alone build to and it works fine ;)

avatar image
0

Answer by mehtanitish · Aug 28, 2018 at 11:20 AM

Hi,

Just want to add that, it will not work when level is reloaded. For it to work you need to stop it before reloading level by using below code line:

webcamTexture.Stop();

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by akilesh0312 · May 03, 2020 at 10:11 PM

hi, @Max-Bot I am getting an orange screen when I run the program in unity. Am I missing something

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fit Canvas to all resolution ? 1 Answer

Dynamically setting gameobject sprites in UI Image 0 Answers

Re-center UI Image after zooming out 0 Answers

ui button in world space not working 0 Answers

Clamp UI Image to Canvas 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges