# Animation : Find time of global min/max position of a given bone

**URL:** <https://forums.unrealengine.com/t/animation-find-time-of-global-min-max-position-of-a-given-bone/425492>\
**Category:** Character & Animation\
**Tags:** bone, unreal-engine, global, question, CPP\
**Created:** [May 19, 2018, 6:11pm UTC](https://forums.unrealengine.com/t/animation-find-time-of-global-min-max-position-of-a-given-bone/425492 "2018-05-19T18:11:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a95c0d08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a95c0d08](https://forums.unrealengine.com/u/anonymous_user_a95c0d08)\
**Post date:** [May 19, 2018, 6:11pm UTC](https://forums.unrealengine.com/t/animation-find-time-of-global-min-max-position-of-a-given-bone/425492/1 "2018-05-19T18:11:37Z")

</div>

Hey,

given a bone and an animation I’d like to get the time when that bone is at it’s highest/ lowest position. ( and then create notifys at those times )

I’ve searched through UAnimSequence and its parents. My idea would be to use

```
UAnimSequence::ExtractBoneTransform(
    const struct FRawAnimSequenceTrack & InRawAnimationTrack,
    FTransform & OutAtom,
    float Time)

```

and interate through the length of the animation to get an array of transforms over the whole animation. But I doubt this will be enough to find the max/min position since the bone is affected by its parents in the hierarchy. So even if I found a min/max position this would be a local min/max and not a global one, right ?

Does anyone know an easier way to do this?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a95c0d08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a95c0d08](https://forums.unrealengine.com/u/anonymous_user_a95c0d08)\
**Post date:** [June 9, 2018, 9:51am UTC](https://forums.unrealengine.com/t/animation-find-time-of-global-min-max-position-of-a-given-bone/425492/2 "2018-06-09T09:51:29Z")

</div>

I solved it with the following code, please correct me if something is wrong

```
int GetFrameOfLowestPosition(UAnimSequence * anim, FName BoneName)
{
	FName ParentBone;
	FTransform Pose;
	FTransform ParentPose;
	TArray<FTransform> Transforms;
	const int32 NumFrames = anim->GetNumberOfFrames();

	for (int i = 0; i < NumFrames; ++i) {
		ParentBone = PlayerMesh->GetParentBone(BoneName);
		UAnimationBlueprintLibrary::GetBonePoseForFrame(anim, BoneName, i, false, Pose);

		while (ParentBone != "None") {
			UAnimationBlueprintLibrary::GetBonePoseForFrame(anim, ParentBone, i, false, ParentPose);
			Pose = Pose * ParentPose;
			ParentBone = PlayerMesh->GetParentBone(ParentBone);
		}

		Transforms.Add(Pose);
	}

	float Minimum = MAX_flt;
	int key = 0;

	for (int j = 0; j < Transforms.Num(); ++j) {
		if (Transforms[j].GetLocation().Z <= Minimum) {
			Minimum = Transforms[j].GetLocation().Z;
			key = j;
		}
	}

	return key;
}

```
