# MovementComponent-\>Velocity is uninitialized. How can I detect this?

**URL:** <https://forums.unrealengine.com/t/movementcomponent-velocity-is-uninitialized-how-can-i-detect-this/1853429>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [May 13, 2024, 5:22am UTC](https://forums.unrealengine.com/t/movementcomponent-velocity-is-uninitialized-how-can-i-detect-this/1853429 "2024-05-13T05:22:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPrecache](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JPrecache](https://forums.unrealengine.com/u/JPrecache)\
**Post date:** [May 13, 2024, 5:22am UTC](https://forums.unrealengine.com/t/movementcomponent-velocity-is-uninitialized-how-can-i-detect-this/1853429/1 "2024-05-13T05:22:35Z")

</div>

I’m trying to predict where a pawn will be. So I’m trying to grab it’s movement component. If it’s got one, the AI should then lead the target.

```auto
if (FocusPawn != nullptr && FocusPawn->GetMovementComponent() != nullptr)
{
		FVector velocity = FocusPawn->GetMovementComponent()->Velocity; //THIS CRASHES!

```

Problem is, it’s got a movement component with an uninitialized velocity, which is a crash. Normally, you’d fix this by initializing it, but that’s EPIC’s code, and they don’t initialize it. I know I can’t check if a variable is initialized at runtime (other than seeing if it crashes.) But is there some other way to tell?

Can I tell if the owning pawn has moved?

The other thing is, the pawn this is happening on doesn’t have a MovementComponent, at least not one I can see in the editor, so why is it passing the nullptr check?

---

<div class="post-metadata">

**Author:** ![JPrecache](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JPrecache](https://forums.unrealengine.com/u/JPrecache)\
**Post date:** [May 13, 2024, 5:54am UTC](https://forums.unrealengine.com/t/movementcomponent-velocity-is-uninitialized-how-can-i-detect-this/1853429/2 "2024-05-13T05:54:01Z")

</div>

The problem was the AActor wasn’t a pawn, so I had to dynamic\_cast it:

`APawn* FocusPawn = dynamic_cast<APawn*>(AIController->GetFocusActor());`
