Search Unity

Question WebCamTexture freezes on play

Discussion in 'Android' started by unity_UUpHGU8iffWR7g, Jun 29, 2022.

  1. unity_UUpHGU8iffWR7g

    unity_UUpHGU8iffWR7g

    Joined:
    Dec 5, 2021
    Posts:
    20
    Hi all,
    I'm working on an android development kit and I'm trying to get the camera feed into unity.
    I've tried a few tutorials and put together this piece of code


    [SerializeField] private RawImage display;

    WebCamDevice device = WebCamTexture.devices[0];
    WebCamTexture camTexture = new WebCamTexture(device.name, 640, 480);
    display.texture = camTexture;
    camTexture.Play();


    I debugged the code and up until the last line everything looks ok. When I run the Play function the app freeze and the debug message I put after is never called. Looks like an endless loop but I can't figure out why.
    Anyone had this problem before? Any tips?

    Thanks!


    PS
    The app works on my android phone but not on the dev board
     
    Last edited: Jun 29, 2022
  2. unity_UUpHGU8iffWR7g

    unity_UUpHGU8iffWR7g

    Joined:
    Dec 5, 2021
    Posts:
    20
  3. unity_UUpHGU8iffWR7g

    unity_UUpHGU8iffWR7g

    Joined:
    Dec 5, 2021
    Posts:
    20
    I'm going to reopen this question. The previous solution was working but is not supported by 3rd party engines like Vuforia. I'm back to square one.
    When I reach the play function, the app freezes with nothing to show in the Android logcat. I can still dismiss and close the app, it's just not responding to any input.

    Ideas?
    Thank you
     
  4. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,025
    Just tested the code below tested in 2 cases: in Awake() and during runtime with a Button.
    For Unity 2021 LTS, Unity 2022 LTS.

    The app (iOS/Android) freezes for a fraction of a second (because it requests a camera stream in the main game thread), and after this, all lines are executed.

    No endless "loop" discovered during testing my Unity Asset called Camera Feed (docs).
    Possible you have something else in your code...
    Code (CSharp):
    1. webCamTextureTarget.Play();
    2.  
    3. rawImage.texture = webCamTextureTarget;
    4.  
    5. PrintAvailableResolutions();
    6.  
    7. PrintSettings();
    8.  
    9. OnInitialized.Invoke();