'Cannot use PhotoCapture by importing 'UnityEngine.Windows.WebCam' by can access UnityEngine.Windows.WebCam.PhotoCapture in Unity

I'm using Unity 2019.4.26f1 (I'm working on a legacy project for my company) and I'm trying to capture images from a Hololens 2 using this official Unity tutorial.

While I've managed to make it work I'd like to understand this behaviour. When I use the classes inside the Webcam namespace, like PhotoCapture, sometimes I get a weird behaviour.

For instance, I can use classes like PhotoCaptureFrame, CapturePixelFormat, among others, but when it comes to PhotoCaptureResult, inside of PhotoCapture, doing PhotoCapture.PhotoCaptureResult doesn't work. The only solution appears to be to use the whole path (UnityEngine.Windows.WebCam.PhotoCapture.PhotoCaptureResult) to access this class. I don't mind doing it but I want to know WHY this happens.

I've checked that I'm using the docs from the right version, and that I've enabled .NET 4.X in my settings, but the issue is still there.



Solution 1:[1]

Hi I’m Wayne Wang from the Microsoft for Founders Hub team!

In my experience, "UnityEngine.Windows.WebCam.PhotoCapture.PhotoCaptureResult" works but a class with a default namespace does not, must be some IL2CPP generation issue: it got confused on namespace.

Please ensure that your projects, your local namespaces, your own classes were not naming as "UnityEngine" "Windows" "WebCam" "PhotoCapture". If it is, please change them.

If it not the case, I would second @billy's advice: Please try update unity, visual studio, and related compiling tools you installed if possible.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wayne Wang - MSFT