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

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?

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?

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:

using System;
using System.Collections.Generic;
using System.Reflection;
using Unity.LiveCapture;
using Unity.LiveCapture.CompanionApp;

public static class ClientUtility
{
    public static IEnumerable<ICompanionAppClient> GetClients()
    {
        var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer");
        var server = UnityEngine.Object.FindObjectOfType(serverType);
       
        var getClientsMethod = serverType.GetMethod("GetClients");
        return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
    }
}

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!

Hi Scott,

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

@DanRP
I’ve tested it and fixed the issue, here is a version that should work:

    public static IEnumerable<ICompanionAppClient> GetClients()
    {
        var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer, Unity.LiveCapture.CompanionApp");
        var server = ServerManager.Instance.CreateServer(serverType);

        var getClientsMethod = serverType.GetMethod("GetClients");
        return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
    }
1 Like

That works! I’m not sure how I would have figured out how to do that on my own.

Thanks again for your help!

1 Like