#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.
  • OnDestroy is called when the task is ended/destroyed. This should be used to clean up any delegates or such if needed. Note: call Super::OnDestroy as the last thing in this function as per recommendation in the UE code for it.