Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Jason-RT-Bond · Mar 09, 2012 at 03:28 PM · webcam

Errors on accessing WebCamTexture.devices

I've been looking into integrating the device camera in a mobile app (iOS and Android), and keep coming across some errors when accessing WebCamTexture.devices.

When devices are available (i.e. on my laptop with a built-in camera and on mobile devices with cameras), the code below works just fine. However, when I run it on my desktop system (which has no camera), I get these errors in the console:

 result == noErr
 UnityEngine.WebCamTexture:get_devices()
 <Start>c__Iterator0:MoveNext() (at Assets/Scripts/Camera/WebCamera.cs:16)

 result == noErr
 UnityEngine.WebCamTexture:get_devices()
 <Start>c__Iterator0:MoveNext() (at Assets/Scripts/Camera/WebCamera.cs:18)

They correspond to the lines where I am using WebCamTexture.devices. (Actually, the first of these lines is my attempt to avoid the error, which obviously doesn't work :P)

The game continues running despite this (it successfully just gets rid of the camera surface via the Destroy() call) so the errors aren't stopping the app, but I feel like it shouldn't be running with errors spewed to the console.

Now, I'm afraid I do not understand what "result == noErr" means and can't find documentation about this. Any ideas on what this issue is and how I can implement this without errors in the console?

 using UnityEngine;
 using System.Collections;
 
 // Basic code borrowed from: http://www.ikriz.nl/2011/12/23/unity-video-remake
 public class WebCamera : MonoBehaviour
 {
     private WebCamTexture webcamTexture;
     
     IEnumerator Start()
     {
         /* First we'll try to go through the list of cameras (if
          * we can) and find a suitable one (not front-facing). */
         bool foundCamera = false;
         string desiredCameraName = "";
         if (WebCamTexture.devices != null)
         {
             for (int i = 0; i < WebCamTexture.devices.Length; i++)
             {
                 // We'd like a camera which is not front-facing.
                 if (!WebCamTexture.devices[i].isFrontFacing)
                     desiredCameraName = WebCamTexture.devices[i].name;
             }
         }
         
         /* If we've got one, we try to get access and then play it. */
         if (foundCamera)
         {
             webcamTexture = new WebCamTexture(desiredCameraName);
             renderer.material.mainTexture = webcamTexture;
             
             yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
             if(Application.HasUserAuthorization(UserAuthorization.WebCam)) 
             {
                 webcamTexture.Play();
             }
         }
         else
         {
             // No camera. So sad. Time to end it.
             Destroy(gameObject);    
         }
    }
 }
Comment
Add comment · Show 1
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 Jean-Fabre · Jun 20, 2012 at 07:17 AM 0
Share

Hi,

I am running into the same issue, when I try to access the device list when there is no device available. I need to access that list even if empty, at least to know it's empty... Did you filled a bug to unity?

1 Reply

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

Answer by Jason-RT-Bond · Jun 21, 2012 at 09:07 PM

I've just reported this to Unity Tech. It seems like a fairly minor issue, but it would be nice if this worked without the weird error spew.

Comment
Add comment · Show 2 · 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 Jason-RT-Bond · Feb 08, 2013 at 12:03 AM 1
Share

Seems to be corrected in the latest version of Unity (4.0.1).

avatar image Jean-Fabre · Feb 08, 2013 at 05:57 AM 0
Share

Very good. thanks for update

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Webcam Support in Unity (iSight or USB Camera) 8 Answers

What is required from a device to be read in a WebcamTexture? 0 Answers

How can i find max resolution for WebCamTexture 2 Answers

Adjust the exposure of phone camera manually 1 Answer

Get FOV of webcam 1 Answer


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