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

Hello,

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

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

			GetCharacterMovement()->SetGravityDirection(GravityDirection);

is not working, output error returns:

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?

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".

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…

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.

1 Like

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