#unreal

Easy to use latent nodes for gameplay purposes. Similar to AITasks

Basic skeleton

UCLASS()
class GAMEJAMREWIND_API UGameplayTask_PlaceItem : public UGameplayTask
{
	GENERATED_BODY()
 
public:
	UGameplayTask_PlaceItem(const FObjectInitializer& ObjectInitializer);
	
	UFUNCTION(BlueprintCallable)
	static UGameplayTask_PlaceItem* PlaceItem(class ANPCCharacterBase* NPC, AActor* Item);
	
	UPROPERTY(BlueprintAssignable)
	FGenericGameplayTaskDelegate OnCompleted;
	
protected:
	virtual void Activate() override;
	
};

Static construction function skeleton:

if(!NPC)
{
	UE_LOG(LogTapeGame, Error, TEXT("Missing character for WaitForItem gameplay task"));
	return nullptr;
}
 
auto* TaskComponent = NPC->FindComponentByClass<UGameplayTasksComponent>();
if(!TaskComponent)
{
	UE_LOG(LogTapeGame, Error, TEXT("Missing task component for WaitForItem gameplay task"));
	return nullptr;
}
 
auto* Task = NewTask<UGameplayTask_WaitForItem>(*Cast<IGameplayTaskOwnerInterface>(TaskComponent));
if(!Task)
{
	return nullptr;
}
 
 
return Task;
  • Constructor can set bTickableTask to false if the task doesn’t need a tick function called.
  • The static function should do basic checks and use NewTask to create the task object
  • FGenericGameplayTaskDelegate properties can be used to create output exec pins from the node for different events
  • Activate is called when the task becomes active, should be used for any logic needed to start actual task execution.