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++?