arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

Can't Destory the model in HumanBodyTracking3D

Open FantasyTianyu opened this issue 7 years ago • 12 comments

If I track a human ,the model will instantiate and update correctly,but when I move the camera out of the people, the log Removing a skeleton [{humanBody.trackableId}]." has not been called. So that the instantiated model will not be destroyed.

foreach (var humanBody in eventArgs.removed)
        {
            Debug.Log($"Removing a skeleton [{humanBody.trackableId}].");
            if (m_SkeletonTracker.TryGetValue(humanBody.trackableId, out boneController))
            {
                Destroy(boneController.gameObject);
                m_SkeletonTracker.Remove(humanBody.trackableId);
            }
        }

FantasyTianyu avatar Dec 02 '19 08:12 FantasyTianyu

The removed list comes from ARKit, and human bodies never get "removed". Use the tracking state to determine when a person has moved out of frame.

tdmowrer avatar Jul 14 '20 22:07 tdmowrer

The removed list comes from ARKit, and human bodies never get "removed". Use the tracking state to determine when a person has moved out of frame.

Do you mean it has no purpose in ARFoundation and is unused? If that is the case, then this fragment of code should be removed because it brings a lot of confusion.

Hypnotistas avatar Sep 21 '20 20:09 Hypnotistas

I mean it is up to the underlying AR framework to decide when to remove a trackable, and while ARKit could decide that a human body will never be tracked again and remove it, in general we have found that if it just goes out of frame for a bit it will change its tracking state but not remove it. So it is not impossible, but the exact situations in which this could happen is an implementation detail in ARKit.

All trackables work this way: the lifecycle is "added", then periodically "updated" with new positions, data, tracking state, etc, then potentially "removed".

tdmowrer avatar Sep 21 '20 20:09 tdmowrer

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 29 '20 00:09 stale[bot]

The removed list comes from ARKit, and human bodies never get "removed". Use the tracking state to determine when a person has moved out of frame.

What is a proper way in case of Human body tracking scene to receive "tracking state" information, doesn't seem to allow to access it.

Hypnotistas avatar Sep 29 '20 08:09 Hypnotistas

The ARHumanBody component has a trackingState property.

In @FantasyTianyu 's snippet, it would be humanBody.trackingState.

tdmowrer avatar Sep 29 '20 22:09 tdmowrer

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 07 '20 04:10 stale[bot]

The ARHumanBody component has a trackingState property.

In @FantasyTianyu 's snippet, it would be humanBody.trackingState.

Something just doesn't make any sense. Could you please provide a specific place where to call: Debug.Log(humanBody.trackingState); ?

Hypnotistas avatar Oct 07 '20 20:10 Hypnotistas

void Start()
{
    GetComponent<ARHumanBodyManager>().humanBodiesChanged += OnHumanBodiesChanged;
}

void OnHumanBodiesChanged(ARHumanBodiesChangedEventArgs eventArgs)
{
    foreach (var humanBody in eventArgs.updated)
    {
        Debug.Log($"human body {humanBody.trackableId} has tracking state {humanBody.trackingState}");
    }
}

tdmowrer avatar Oct 07 '20 22:10 tdmowrer

void Start()
{
    GetComponent<ARHumanBodyManager>().humanBodiesChanged += OnHumanBodiesChanged;
}

void OnHumanBodiesChanged(ARHumanBodiesChangedEventArgs eventArgs)
{
    foreach (var humanBody in eventArgs.updated)
    {
        Debug.Log($"human body {humanBody.trackableId} has tracking state {humanBody.trackingState}");
    }
}

So that's what I had in mind. This is not a correct approach. Once the body tracking is lost (tracking of the body doesn't happen) this update part is never reached, so Debug.Log() wouldn't be called. I've tried it before. Of course, it would be ok if the body tracking takes place, but we need to get the trackingState value once that body tracking is lost.

Hypnotistas avatar Oct 08 '20 08:10 Hypnotistas

When I run this, if the human I am tracking moves out of frame, I get one "updated" event with trackingState None. After that, I get no further updates on that human until they are tracked again. This is the expected behavior. Are you seeing something different?

If you want to know the tracking state of a particular human body at any given time, you can iterate all of them with ARHumanBodyManager.trackables or get a specific one by id with ARHumanBodyManager.GetHumanBody.

tdmowrer avatar Oct 09 '20 01:10 tdmowrer

Hello. You are right! We get 1 frame! Awesome! Problem solved! Thanks!

Hypnotistas avatar Oct 12 '20 19:10 Hypnotistas