bakjos / WebCameraFeed

Web Camera plugin for Unreal Engine
63 stars 29 forks source link

Cannot display multiple webcams simultaneously [but I can, using workaround] #1

Closed DarioMazzanti closed 6 years ago

DarioMazzanti commented 6 years ago

Issue

Hi! Thanks so much for the plugin! I just started to use it this morning to test some webcams in UE4. I plugged my webcam and I managed to display it very easily in a scene :)

Anyway, I found some unexpected behaviour when trying multiple webcams are connected to the computer. I am using the CameraPlane_BP provided with the plugin.

How to reproduce:

  1. Put 2 CameraPlane_BPs in a scene (let's call them Plane_A and Plane_B)
  2. Plane_A: select a camera from the WebCameraComponent DeviceId droplist.
  3. Plane_A: select a different camera on the second CameraPlane_BP
  4. Play your scene: Plane_A and Plane_B will both show the feed from the same camera.

Another way to reproduce the issue is to just put a single Plane in a scene, and select a DeviceId which is different from the first one of the available devices list.

I am using Unreal Engine 4.19.2 on Windows 10.

Clues?

When choosing a DeviceId from the WebCameraComponent droplist in the editor, the editor interface for the component disappears. Then, if I select again the component to check if the device selection worked out, I can see that the selected DeviceId is the first one from the list, no matter which one I choose.

So, I suspect there might be some issue with the WebCameraDeviceIdCustomization class.

Workaround

I took a look at the code of the WebCameraComponent .h and .cpp files, and I exchanged the DeviceId.selectedDevice with an int UPROPERTY I added, called MyDeviceId.

e.g.:

// Called when the game starts
void UWebCameraComponent::BeginPlay()
{
    Super::BeginPlay();
    currentVideoGrabber = VideoGrabberPool::GetVideoGrabber(MyDeviceId, requestedWidth, requestedHeight, MirroredVideo);

}

If I use this added integer instead of the provided DeviceId.selectedDevice variable, I can see the 2 different feeds on Plane_A and Plane_B.

bakjos commented 6 years ago

Hi Dario,

Thanks for reporting this issue, the problem was with the property customization to show the available devices, when the component was saved it was reseting the value to zero, so it took the first device always, i've just uploaded a new commit to fix this, let me know if that works

DarioMazzanti commented 6 years ago

Hi there, Thanks for such fast feedback!

I am trying it right now, and it seems like the setting is now working in the editor: I can select a different device id and the interface will show the selected one. Anyway, there was something which was still preventing the correct webcam to be selected, but it's easier to fix!

Inside the CameraPlane_BP, on BeginPlay, there is a branch which checks if the project is running on mobile (iOS or Android), and based on that the blueprint decides whether to leave the DeviceId as it is, or to get the front camera id of the device.

I did not pay much attention to that until now: the branch is swapped, and so if the device is NOT a mobile one, the blueprint tries to get the front camera Id as its DeviceId. This results in the first camera always being selected, no matter what.

By connecting the GetFromCameraId block to the True exec pin of the branch (instead of False) everything works perfectly.

Thank you again for this plugin!

bakjos commented 6 years ago

Hi Dario,

Yes I forgot to change it inside the example blueprint, because I'm using a different BP inside to test the plugin. I've just uploaded a new version and now I'll close this issue