# Custom Gravity c++ How can i access the MovementComponent functionality from Character class?

**URL:** <https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [November 19, 2024, 1:06pm UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208 "2024-11-19T13:06:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zombie.SoC1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zombie.SoC1](https://forums.unrealengine.com/u/Zombie.SoC1)\
**Post date:** [November 19, 2024, 1:06pm UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208/1 "2024-11-19T13:06:55Z")

</div>

Hello,

since 5.4 the custom gravity functionality is accessable in BP via the character class and its MovementComponent.

 ![grafik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/2/e928fe7bfaee67d41ab9145c79269e63e47d7e3d.png)

I want to do the same thing in c++ and running into the trouble that i cant access the movement component.

```auto
			GetCharacterMovement()->SetGravityDirection(GravityDirection);

```

is not working, output error returns:

```auto
2>AxCharacter.cpp(190): error C2027: use of undefined type 'UCharacterMovementComponent'
2>...\Engine\Classes\GameFramework\Character.h(25): note: see declaration of 'UCharacterMovementComponent'

```

So can i access the character Movement Component from a character class derived script?

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [November 21, 2024, 8:48am UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208/2 "2024-11-21T08:48:17Z")

</div>

`Use of undefined type` means that you need to `#include` the header .h file where the type is declared.  
In this case it would be `#include "GameFramework/PawnMovementComponent.h"`.

---

<div class="post-metadata">

**Author:** ![Zombie.SoC1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zombie.SoC1](https://forums.unrealengine.com/u/Zombie.SoC1)\
**Post date:** [November 29, 2024, 3:45pm UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208/3 "2024-11-29T15:45:11Z")

</div>

thanx for your reply !  
it did help with using  
#include “GameFramework/CharacterMovementComponent.h”,

i just wondering a bit, as this is already defined in the parentclass…

---

<div class="post-metadata">

**Author:** ![silnarm](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/silnarm/32/955303_2.png) [@silnarm](https://forums.unrealengine.com/u/silnarm)\
**Post date:** [November 30, 2024, 12:21am UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208/4 "2024-11-30T00:21:54Z")

</div>

It certainly isn’t defined in the parent class, and is only `forward declared` there (see line 25 of Character.h), to use it you need the full declaration; the forward dec lets you declare pointers to the type without having to bring in the whole declaration, which is very useful in header files to avoid circular dependencies and reduce compile times.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 30, 2024, 12:22am UTC](https://forums.unrealengine.com/t/custom-gravity-c-how-can-i-access-the-movementcomponent-functionality-from-character-class/2135208/5 "2024-12-30T00:22:47Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
