How to play haptic feedback on Motion Controller in C++

I’ve found the method “PlayHapticEffect” in the PlayerController class. Ideally I would want to do this

void UCustomMotionController::PlayHapticFeedback()
{
    UGameplayStatics::GetPlayerController(GetWorld(), 0)->PlayHapticEffect(mHapticFeedback, MyHand);
}

Where mHapticFeedback is a UHapticFeedbackEffect_Base object.

The problem is: how the heck should I load the feedback asset?

This doesn’t work:

ConstructorHelpers::FObjectFinder<UHapticFeedbackEffect_Base> hapticFeedbackFinder(TEXT("/Game/HapticFeedback/HapticImpulse.HapticImpulse"));
mHapticFeedback = hapticFeedbackFinder.Object;

It doesn’t work because UHapticFeedbackEffect_Base doesn’t derive from UObject. So, how should I load it?

I’ve also found another method called SetHapticsByValue, which has this signature:

void PlayHapticEffect(class UHapticFeedbackEffect_Base* HapticEffect, EControllerHand Hand, float Scale = 1.f,  bool bLoop = false);

It kinda works, meaning that if I call it the controller does vibrate, but after it stops it doesn’t vibrate anymore if I call that function.

So I’m at a loss, is it really that hard to play haptic feedback in C++?

Actually, I tried adding this include:

#include "Haptics/HapticFeedbackEffect_Base.h"

and the first method works. I don’t know why it was telling me that it doesn’t derive from UObject while it shouldn’t even find the class in the first place.

Nice catch, still same in 4.17