How to create an output exec pin for a c++ function

Can you explain what your variation to the MoveToLocation is intended to do? There is a chance that there is a way to do what you want without having to create a custom node.

In my experience, you will need to bind delegates for any latent action in C++ for navigation. I would be happy to learn if i am wrong. As far as the navigation system works, there are a couple steps of which you appear already to be on the trail. First, we make a move request, I cant remember offhand if this is latent, but i think so. IIRC, we bind to the event that the request has been handled and we now have a path to follow. Next we bind to the move completed event which could either succeed or fail. Upon completion of the move, which could take an arbitrary amount of time, we can then throw an event based on the result of the move itself.

You can also bind to events for on path segment completed. I know this doesnt answer your question outright, but i hope it helps a little.

1 Like

Bear in mind, I’m still wrapping my head around delegates. I understand them in general I think.

I’ve created a minor variation on MoveToLocation in my AIController derived class. Looking into the MoveToLocationOrActor node, I’ve found:

	UPROPERTY(BlueprintAssignable)
	FMoveTaskCompletedSignature OnMoveFinished;

I see that PathFollowingComponent has a delegate FMoveComplete OnRequestFinished; that AITask_MoveTo binds their own OnRequestFinished to, which leads to FinishMoveTask which eventually leads to OnMoveFinished.Broadcast.

I assume that on the MoveToLocationOrActor node, the OnMoveFinished pin is somehow bound to OnMoveFinished. How can I recreate this? Am I going to have to create an entirely new BP node?

I copy/pasted the MoveToLocationOrActor node into a notepad, which led me to UK2Node_LatentGameplayTaskCall, but a lot of that is above my head currently.

Or is the fact that I’m using a function out of AIController and not a custom AITask the issue with recreating that node.

The reason I’m looking for a node form is I have a blueprintnativeevent that takes in a task as a param. In BP it calls my custom moveto function, and on MoveFinished I’d like to call the c++ portion of the native event.
At the moment I’m not clear enough with how delegates and the source code surrounding navigation works to do this all through c++, which I would prefer.

There 3 options:

-Create latent function

It does not require K2Node. It requires to set up fucntion properly and create class that will deal with tracking of task you waiting to be completed. I didn’t explore htis myself so all i can do is link:

http://johnmcroberts.com/index.php/2017/11/30/custom-delayed-blueprint-function-in-c/

-Create oyur own K2Node

You aware of this one, you can make a node that does the job. It’s most defficult option

-Use delegate pin

It’s little bit scachy as it’s been implemented for perticilar case (timer nodes) but you can use delegate as a function argument and mind delegate to delegate. On node it will apper as red square same as in timer nodes and oyu would use it same way. Problem is this only works with FTimerDelegate (atleast that only one i know), you might try to so something use TBaseDynamicDelegate or TBaseDynamicMulticastDelegate. But FTimerDelegate can be also easily use it’s normal dynamic delegate with no arguments so. If oyu interested i could dive in to my older project to see how it made it work ( i did make it work ;])

1 Like

Every insight helps so thank you.
I’m doing this because from the custom “MoveToTarget”, I call an overriden “MoveTo” which calls an overriden “FindPathForMoveRequest”. Inside FindPathForMoveRequest, I get a path regularly, but then I find the centerpoint along that path, bring the next navpoint to that location and remove the rest, and return this updated path.
I don’t want to place this in my overridden RecastNavMesh::FindPath since I only want to do this between AI during battles.

I will definitely dive into latent functions, as I’m only just starting to read through how source code handles latent functions, and I hadn’t heard of them prior (amateur programmer :] ).
Ideally I want to keep this within c++, since it’s more trackable.

I’ll mark this as my answer since you and @ZeroParadigm both mentioned latent functions and delegate usage as the way. I’ll just need to dive into how the source uses them. Thanks for the answer!

The link above provided is really helpful, but I also wanted to point out that if you’re doing a latent action, that you want to be able to trigger multiple different pins (such as start, end, progress, failure, etc), you can setup as many pins as you want to the function with ExpandEnumAsExecs … then you pass your reference to the enum down to the LatentAction … and the LatentAction can set that enum reference to whatever value it wants and then call Response.TriggerLink in it’s UpdateOperation.

I… can’t provide source right at the moment, but… pass your Enum ref to your LatentAction constructor, store it in the LatentAction, then in LatentAction’s UpdateOperation(), set the stored Enum ref to whichever value you want to trigger, then call TriggerLink().