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?