Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Live Capture: How do I access the currently connected clients and update Face Device in script?

Discussion in 'Virtual Production' started by DanRP, May 18, 2022.

  1. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    Hello,

    I'm using Live Capture and I currently have to manually select the Client Device in the Face Device object every time I run my app (see attached screenshot). I would like to update this property programmatically in script.

    I need to do 2 things:

    1) Find a way to get a list of currently connected clients as seen in the Live Capture > Connections window (see attached screenshot).

    2) Assign the active client device to the Client Device property of the ARKit Face Device object. I assume that I would use the ARKit Face Device method SetClient().

    How do I get the currently active Live Capture device as a FaceClient object?
     

    Attached Files:

  2. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    As I research this more, it looks like I would need to get access to: CompanionAppServer. However, CompanionAppServer is private and cannot be accessed.

    How can I access CompanionAppServer from script?
     
  3. ScottSewellUnity

    ScottSewellUnity

    Unity Technologies

    Joined:
    Jan 29, 2020
    Posts:
    20
    You are correct that currently there is no public access to the client list.
    For now, you can use reflection to access the clients, something like this:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Reflection;
    4. using Unity.LiveCapture;
    5. using Unity.LiveCapture.CompanionApp;
    6.  
    7. public static class ClientUtility
    8. {
    9.     public static IEnumerable<ICompanionAppClient> GetClients()
    10.     {
    11.         var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer");
    12.         var server = UnityEngine.Object.FindObjectOfType(serverType);
    13.        
    14.         var getClientsMethod = serverType.GetMethod("GetClients");
    15.         return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
    16.     }
    17. }
    18.  
    I've not tested it, but the general approach should work. Since this uses reflection, it is not guaranteed to work going forwards, but should work in the mean time until this functionality is exposed publicly. I hope this helps!
     
  4. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    Hi Scott,

    Thanks so much for your response! The code compiles, but serverType appears to be null after the "Type.GetType()" call. Any ideas?
     
  5. ScottSewellUnity

    ScottSewellUnity

    Unity Technologies

    Joined:
    Jan 29, 2020
    Posts:
    20
    @DanRP
    I've tested it and fixed the issue, here is a version that should work:
    Code (CSharp):
    1.  
    2.     public static IEnumerable<ICompanionAppClient> GetClients()
    3.     {
    4.         var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer, Unity.LiveCapture.CompanionApp");
    5.         var server = ServerManager.Instance.CreateServer(serverType);
    6.  
    7.         var getClientsMethod = serverType.GetMethod("GetClients");
    8.         return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
    9.     }
    10.  
     
    marc_tanenbaum likes this.
  6. DanRP

    DanRP

    Joined:
    May 26, 2013
    Posts:
    33
    That works! I'm not sure how I would have figured out how to do that on my own.

    Thanks again for your help!
     
    marc_tanenbaum likes this.