I am trying to play force feedback when I am pulling back on a string for my bow in c++ code but not exactly sure how to do so. Any suggestions ?
bump, I am wondering too.
Going to answer this, because I was searching for an answer myself today and could not find any. Just in case anyone is still running into the same problem.
The solution should actually be quite straight forward. PlayDynamicForceFeedback
is a public member of PlayerController
so if you have access to your PlayerController
you can just call PlayDynamicForceFeedback
on it. Right?
FLatentActionInfo latentInfo;
PlayerController->PlayDynamicForceFeedback(Intensity, Duration, bAffectsLeftLarge, bAffectsLeftSmall, bAffectsRightLarge, bAffectsRightSmall, EDynamicForceFeedbackAction::Start, latentInfo);
NO, you can not JUST call it. When you do it like this your dynamic force feedback is not processed. Which is very unexpected.
But why? I had to do some code digging to find this. Internally dynamic force feedback is added to the LatentActionManager
as a latent action and will be destroyed by it without being processed if it had no callback target specified. Which is not documented anywhere where I would be searching when I am wondering why my dynamic force feedback is not being processed and I am all like “They certainly wouldn’t expect me to provide a CallbackTarget if I don’t even want to receive any callbacks.”
So what you actually need to do for the dynamic force feedback to be processed and not garbage collected is provide a CallbackTarget
in your latentInfo and viola dynamic force feedback is playing.
FLatentActionInfo latentInfo;
latentInfo.CallbackTarget = SomeUObjectThatIsNoNullPointer; // in my case I did not care about when the force feedback finishes so I just provided the PlayerController here, you can pass whatever you need to
PlayerController->PlayDynamicForceFeedback(Intensity, Duration, bAffectsLeftLarge, bAffectsLeftSmall, bAffectsRightLarge, bAffectsRightSmall, EDynamicForceFeedbackAction::Start, latentInfo);
In the blueprint documentation it looks like the ‘Target’ is supposed to be the player. Not sure if it’s a one to one correlation between ‘Target’ and ‘CallbackTarget’.
‘PlayDynamicForceFeedback’ is a member of APlayerController. The ‘Target’ for the blueprint node is the object ‘PlayDynamicForceFeedback’ is called on and there is no correlation between ‘Target’ and ‘CallbackTarget’ as ‘CallbackTarget’ is a member of ‘FLatentActionInfo’.
In blueprint you do not need to create the ‘FLatentActionInfo’ yourself, it is handled by what I call blueprint magic, which will also provide a ‘CallbackTarget’.