How to bind to AI Move To completed?

Hi! I’m trying to bind the OnMoveCompleted results from AIController->MoveToActor(Actor) to a different class. My StateMachine is executing the function and i want it to be informed when the destination was reached. Searching for hours but can’t wrap my head around it. I’m new to C++.
Also: Do I have to unbind the function after each movement to rebind it? If i bind more than once, the function will be called multiple times right?

If i bind more than once, the function will be called multiple times right?

You might crash your engine or fill your memory into oblivion doing that. Anywhere. Never bind something double, make sure the last function was unbound first.

Hi! I’m trying to bind the OnMoveCompleted results from AIController->MoveToActor(Actor) to a different class

I’m not quite sure what you want to do here. You want to have that function call a function in another class?

1 Like

Thanks! Seems dangerous to use binding then.
I think I kinda got it working now. I’m binding with:
Controller->GetPathFollowingComponent()->OnRequestFinished.AddUObject(this, &AMyClass::OnMoveToCompleted);

And unbinding with:
Controller->GetPathFollowingComponent()->OnRequestFinished.RemoveAll(this);

3 Likes

What you’re doing looks reasonable. You can also store an FDelegateHandle (return val of AddXXX functions) and remove that explicitly; you’re also allowed to remove the handle inside the callback.

1 Like