Search Unity

Xperia phone has a built-in camera button which is not working when playing Unity game

Discussion in 'Android' started by roxuko, Aug 20, 2017.

  1. roxuko

    roxuko

    Joined:
    Apr 30, 2015
    Posts:
    1
    Currently testing my games made with Unity with an Xperia Z5. This phone has a built-in camera button at the side, which will usually trigger the camera application when long-pressed. However, when playing these Unity games, the camera button is unable to work - nothing happens when the button is pressed.

    An example of how the camera button looks like on Xperia phones:


    I'm trying to get the camera button to work as usual, which is to call up the camera app, why is the button unable to work when a unity game is playing?
     
  2. FlashyGoblin

    FlashyGoblin

    Joined:
    Apr 1, 2017
    Posts:
    23
    Have you ever found a solution to this? I am trying to access the front facing camera within Unity and this device fails and shows an error

    E/Unity: Camera2: Error opeining CameraDevice 4
     
    ROBYER1 and kayy like this.
  3. kayy

    kayy

    Joined:
    Jul 26, 2011
    Posts:
    110
    I run into similar issues like @FlashyGoblin with an old Z4 tablet when accessing the back camera. Strange enough that after the app loses the focus and gets it again, everything works as expected.
     
    ROBYER1 likes this.
  4. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    Sorry to resurrect an old thread but I am experiencing this with Unity 2019 and 2020, did you have a fix? Same behaviour camera doesn't work until app is opened once then again and screen is turned off and on again

    EDIT: I found the fix, turns out you need to set the Webcamtexture FPS to 30 for it to work on all phones

    Something like this, where the 30 is the requested fps :)

    Code (CSharp):
    1. cameraTexture = new WebCamTexture(curr.name, Screen.width, Screen.height, 30);
     
    Last edited: Feb 1, 2021
    VMinnovation likes this.