How to keep tracking the first recognized user?

Is there a setting to track only the first recognized user until his tracking lost?
So that the others walking in front of the camera will not affect the tracking.
I tried to SetNumActiveUsers to 1 but if there is another one walking in front of the camera the currentSkeleton is switched to the walking person.

In your case, the best possible option would be to track all the skeletons and take into account the presence of a skeleton for a specific / selected user. For example:

        SkeletonData::Ptr skeletonData;
        UserFrame::Ptr userFrame;
        int main_user_id = -1;

        // ...

        if (main_user_id == -1 && userFrame)
		{
			auto  users = userFrame->getUsers();
			if(!users.empty())
				main_user_id = users[0].id; // fix random user
		}

        // ...

		if (skeletonData)
		{
			for (auto skeleton : skeletonData->getSkeletons())
			{
				if(skeleton.id == main_user_id)
				{
					// display the chosen user
				}
			}
		}

I changed the CurrentUserTracker.cs according to your suggestion.
But it seems not working…maybe I did something wrongly?
Here is the code:

void NuitrackManager_onUserTrackerUpdate(nuitrack.UserFrame userFrame)
{
    if (userFrame.Users.Length > 0)
    {
        if (main_user_id == -1)
        {
            main_user_id = userFrame.Users[0].ID;
            Debug.Log("NuitrackManager_onUserTrackerUpdate - main_user_id  : " + main_user_id);
        }
    }
    else
    {
        main_user_id = -1;
    }

}
void NuitrackManager_onSkeletonTrackerUpdate(nuitrack.SkeletonData skeletonData)
{
    if ((skeletonData == null) || (skeletonData.NumUsers == 0))
    {
        currentUser = 0;
        currentSkeleton = null;
        return;
    }

    if (currentUser != 0)
    {
        for (int i = 0; i < skeletonData.NumUsers; i++)
        {
            if (skeletonData.Skeletons[i].ID == main_user_id)
            {
                //Debug.Log("NuitrackManager_onSkeletonTrackerUpdate - currentUser  : " + currentUser);
                currentSkeleton = skeletonData.Skeletons[i];
                currentUser = (currentSkeleton == null) ? 0 : currentUser;
            }
        }
    }

    if (currentUser == 0)
    {
        currentUser = skeletonData.Skeletons[0].ID;
        currentSkeleton = skeletonData.Skeletons[0];
    }
}

If the second person is moving in front of the camera, blocking the first one, then tracking may be lost.
Tracking can also get lost when frames are skipped.
Nuitrack can lose tracking when one user overlaps the second user. Try to set an active area (a marker in space), in which the user will always be considered as the main one. You can do this with a trigger box-collider or by checking the position of any joint for a given range.

Do you have “box collider” functional in nuitrack libriary or self-realization is supposed?

Dear Alexandr Ussik.

You need to implement this function yourself. It won’t be difficult.

Here are a couple of tips:

  1. First, you need to add any collider (for example, Capsule Collider) to your Avatar model. Add Rigidbody component and set the isKinematic = true flag. To highlight it among other possible objects, you can add a tag.

  2. For the detector object, adjust the position on the stage and add the BoxCollider component, set the isTrigger = true flag, and adjust its dimensions.

  3. Next, create a script and attach it to the detector object and implement the OnTriggerEnter(Collider) method, where collider of Avatar can be filtered by tag.

Please let me know if you have any other questions.