Pointers from UCharacterMovementComponent are not working

Hi, I’m trying to get the acceleration of my character using this code:

GetCharacterMovement()->GetCurrentAcceleration()
But it the compiler is returning the error:
error C2027: use of undefined type ‘UCharacterMovementComponent’

note: see declaration of ‘UCharacterMovementComponent’

error C2227: left of ‘->GetCurrentAcceleration’ must point to class/struct/union/generic type

I’m sure I’ve used this in the past, but idk what I could be missing now.

1 Like

Add

#include "GameFramework/CharacterMovementComponent.h"

to the top of your source file. A lot of headers were moved out of the global monolithic headers in 4.15 and must be included as you use them.

4 Likes

It works! Thanks

Quick (dumb) question, should VS automatic import those headers? If not, how can I know which header to import?

No, VS won’t automatically find all the headers for you and add the references (previously the monolithic headers did that at the cost of a longer compile time). You need to manually specify them now.

Most (like 95%) of classes are found in files that use the same name (i.e. UCharacterMovementComponent is in CharacterMovementComponent.h which is in the GameFramework directory, hence “GameFramework/CharacterMovementComponent.h”).

I normally just search for the class name (if you use Visual Assist, you can just type ALT+SHIFT+O and it’ll bring up all files in the solution, and you can search that way). Or simply do a find in files for the class name and find where it’s declared.

No, I’m not using Visual Assist, but I’m able to use Intellisense to find the class definition.

Thanks again.