Binding to UPathFollowingComponent OnRequestFinished Event

So I’m trying to bind to UPathFollowingComponent::OnRequestFinished, it needs 2 arguments:

FAIRequestID , const FPathFollowingResult &.

Here’s what I’ve done:

In my header I forward declare the appropriate types, and declare my method to bind.

struct FAIRequestID;
struct FPathFollowingResult;

UFUNCTION()
void OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result);

In my cpp file, I include the appropriate headers, and bind the method in beginplay:

#include "AIController.h"
#include "Navigation/PathFollowingComponent.h" //Where FPathFollowingResult lives
#include "AITypes.h" //Where FAIRequestID lives

/* in begin play ...*/
AAIController* AI = Cast<AAIController>(GetController());
UPathFollowingComponent* PathFollowingComponent = AI->GetPathFollowingComponent();
if (AI)
{
	PathFollowingComponent->OnRequestFinished.AddUObject(this, &AFPSAIPatrolGuard::OnMoveCompleted);
}

My Problem:
I keep getting the following compilation error:
Unrecognized type ‘FPathFollowingResult’ - type must be a UCLASS, USTRUCT or UENUM.

EDIT:
I’ve dug into FPathFollowingResult declaration in the source files, and it’s actually not marked with a USTRUCT(), so the error message is just stating the truth, but if that’s the case, then what IS the problem here?

What I’ve tried:
EDIT: I’ve tried Including the headers in my header file and removing the forward declarations.

I spent 3 hours googling, and only thing that came up was this post:

I’m at lost here, anyone has an idea?

Thanks for the reply, tried it now, sadly it didn’t solve the problem: got the same error message.

have you tried include the header for PathFollowingComponent.h in your AFPSAIPatrolGuard header

I had the experience that unreal code generation sometimes has problems with forward declarations.

What happens if you take
#include “Navigation/PathFollowingComponent.h”
out of the cpp and put it in the h, then remove the forward declaration?

You could introduce circular dependencies this way but it’s a quick fix to see if it resolves the issue.

Same error :frowning:

I’ve checked FPathFollowingResult declaration in the source files, it’s actually not marked with a USTRUCT(), so maybe something about the entire process is just wrong?

K had a little look around apparently if you bind something with the AddUObject method it doesn’t have to be a UFUNCTION

go figure…
so remove that and it should be fine.

example for that in the engine would be in AITask_MoveTo.h

3 Likes

This works!
Thank you very much!

This also worked for me, thank you!

Thank you.