Skip to content

Programming Guide

Michael Adaixo edited this page Dec 28, 2023 · 14 revisions

FlowPilot Task Node

Each TaskNode will finish when its Tick() method returns anything different than EFPNodeREsult::InProgress. If you don't override FPTaskNode::Tick(), the task will automatically Succeed after entering. If you need to wait, you have to override this method, and return your own value. See FPTask_Delay or other for reference.

FlowPilot Node Implementable Methods

See [InsertPage] FlowPilot Architecture page for lifecycle reference.

UFPNode Interface

// UFPNode
// One time setup at the start of the FlowPilot Execution.
virtual void Setup(FFlowContext* InContext);
//~UFPNode

This is called once at the start of FlowPilot execution, for all Tasks in the FlowPilot Asset.

UFPTaskNode Interface

// UFPTaskNode
// Called when starting this Node. Returns true on success
virtual bool Enter();
// Called on Tick. Will success automatically if not implemented by Child classes
virtual EFPNodeResult Tick(float DeltaTime);
// Called when Tick returns Succeeds
virtual void Exit();
// Called when FlowPilotComponent calls Abort.
virtual void Abort();

// !! Implement if Task has Child TaskNodes !!
// Returns true if has ChildNodes
virtual bool HasChildNodes() const { return false; }
// Returns the list of ChildNodes
virtual void GetChildNodes(TArray<TObjectPtr<UFPTaskNode>>& OutChildNodes) PURE_VIRTUAL(,)
// Returns the number of ChildNodes
virtual uint32 GetNumChildNodes() const { return 0; }
//~UFPTaskNode

FlowPilot Instant Node

// UFPInstantNode
// Called when FPTaskNode calls OnExit or OnEnter
virtual void Execute() {};
//~UFPInstantNode

New FlowPilot Task Node Class

Example "Open Door" interation

UCLASS(DisplayName="Interaction | Open Door")
class MYGAME_API UFPTask_OpenDoor : public UFPTaskNode
{
	GENERATED_BODY()
	
public:
	UFPTask_OpenDoor();
	
	virtual void Setup(FFlowContext* InContext) override;
	virtual bool Enter() override;

protected:
	// First Actor Tag
	UPROPERTY(EditAnywhere, Category = "Flow Pilot")
	FFlowActorReference ActorReference;

private:

};

This Task doesn't tick and will return Success automatically after Enter() is called, on the next Tick frame.

Example Implementation:

bool UFPTask_OpenDoor::Enter()
{
	AActor* Actor = FindActor(ActorReference);
	if (!IsValid(Actor))
	{
		return false;
	}

	ASingleDoor* SingleDoor = Cast<ASingleDoor>(Actor);
	if(!IsValid(SingleDoor))
	{
		return false;
	}
	
	return SingleDoor->OpenDoor(GetFlowOwningActor());
}

New Blueprint based FlowPilot Class

To make a new FlowPilot Class in Blueprint.

  1. Create new Blueprint.
  2. Select FPTask_BlueprintBase or FPInstant_BlueprintBase

image

  1. Implement needed virtual methods with implementation details.

image

  1. Add need variables. For example, you'll want to add FFlowActorReferences so that you can tap into the FlowPilot System, of finding actors on scene, track and finding them via GameplayTags.

image

Example implemetation of Turning an Array of Lights On/Off image

  1. Setup and Profit

image

Clone this wiki locally