You can use ThisClass instead of the class name for binding callbacks

When binding methods in unreal C++, you can use the ThisClass typedef rather than using your classes name, this works like Super, both typedefs are created in the GENERATED_BODY() macro. Also, its since it’s safe to refer to parent class members from the child classes scope unless you trying to access an overridden functions you can actually set up input binding as follows:

PlayerInputComponent->BindAxis(TEXT("MoveX"), this, &ThisClass::MoveX);
PlayerInputComponent->BindAxis(TEXT("MoveY"), this, &ThisClass::MoveY);
PlayerInputComponent->BindAxis(TEXT("LookPitch"), this, &ThisClass::AddControllerPitchInput);
PlayerInputComponent->BindAxis(TEXT("LookYaw"), this, &ThisClass::AddControllerYawInput);

This has the advantage of not having to change binding when you copy them to another class or rename your class.

6 Likes

Love these great pieces of information. Wish there was a good course that taught the efficient code for C++ with Unreal. These courses are great but not always the “best” code.

Good tip.

Privacy & Terms