Import helper plugin
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
// Copyright (c) 2026 Unreal Directive. Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "UObject/SoftObjectPtr.h"
|
||||
#include "DirectiveUtilTask_AsyncLoadAsset.generated.h"
|
||||
|
||||
struct FStreamableHandle;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncLoadAssetCompleted, UObject*, LoadedAsset);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncLoadClassCompleted, UClass*, LoadedClass);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncLoadAssetsCompleted, const TArray<UObject*>&, LoadedAssets);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnAsyncLoadAssetsProgress, int32, LoadedCount, int32, TotalCount);
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_AsyncLoadAsset
|
||||
* Asynchronously loads a soft object reference and broadcasts the loaded asset, with a cancel option.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Load Asset"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_AsyncLoadAsset : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Asynchronously loads the asset referenced by a soft object pointer.
|
||||
* The Completed delegate is called with the loaded asset on success; the Failed delegate is called with null on failure. A manual Cancel() does not broadcast Failed.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Asset The soft object reference to load.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|AssetManagement",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Load Asset"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncLoadAsset* AsyncLoadAsset(UObject* WorldContextObject, const TSoftObjectPtr<UObject> Asset);
|
||||
|
||||
/**
|
||||
* Cancels the in-progress load. The Failed delegate is not broadcast for a manual cancel.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|AssetManagement")
|
||||
void Cancel();
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
// Called when the asset has finished loading. The loaded asset is valid.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadAssetCompleted Completed;
|
||||
|
||||
// Called when the load failed. The loaded asset is null.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadAssetCompleted Failed;
|
||||
|
||||
protected:
|
||||
|
||||
TSoftObjectPtr<UObject> SoftAsset;
|
||||
TSharedPtr<FStreamableHandle> StreamableHandle;
|
||||
|
||||
void OnLoaded();
|
||||
};
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_AsyncLoadClass
|
||||
* Asynchronously loads a soft class reference and broadcasts the loaded class, with a cancel option.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Load Class"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_AsyncLoadClass : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Asynchronously loads the class referenced by a soft class pointer.
|
||||
* The Completed delegate is called with the loaded class on success; the Failed delegate is called with null on failure. A manual Cancel() does not broadcast Failed.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param AssetClass The soft class reference to load.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|AssetManagement",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Load Class"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncLoadClass* AsyncLoadClass(UObject* WorldContextObject, const TSoftClassPtr<UObject> AssetClass);
|
||||
|
||||
/**
|
||||
* Cancels the in-progress load. The Failed delegate is not broadcast for a manual cancel.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|AssetManagement")
|
||||
void Cancel();
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
// Called when the class has finished loading. The loaded class is valid.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadClassCompleted Completed;
|
||||
|
||||
// Called when the load failed. The loaded class is null.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadClassCompleted Failed;
|
||||
|
||||
protected:
|
||||
|
||||
TSoftClassPtr<UObject> SoftClass;
|
||||
TSharedPtr<FStreamableHandle> StreamableHandle;
|
||||
|
||||
void OnLoaded();
|
||||
};
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_AsyncLoadAssets
|
||||
* Asynchronously loads a batch of soft object references in a single request and broadcasts the
|
||||
* loaded assets, with progress updates and a cancel option.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Load Assets"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_AsyncLoadAssets : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Asynchronously loads the assets referenced by an array of soft object pointers in a single request.
|
||||
* The Completed delegate is called exactly once with the loaded assets in input order; entries that were
|
||||
* unset or failed to resolve are null. An empty input array completes immediately with an empty array.
|
||||
* A manual Cancel() does not broadcast Completed.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Assets The soft object references to load.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|AssetManagement",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Load Assets"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncLoadAssets* AsyncLoadAssets(UObject* WorldContextObject, const TArray<TSoftObjectPtr<UObject>>& Assets);
|
||||
|
||||
/**
|
||||
* Cancels the in-progress load. The Completed delegate is not broadcast for a manual cancel.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|AssetManagement")
|
||||
void Cancel();
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
// Called exactly once when the batch has finished loading. The assets are in input order with null
|
||||
// entries for references that were unset or failed to resolve, and are only guaranteed alive during
|
||||
// this broadcast.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadAssetsCompleted Completed;
|
||||
|
||||
// Called as assets arrive, with the number loaded so far and the total requested. Not called when
|
||||
// the request finishes before the first update (e.g. all assets were already in memory).
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncLoadAssetsProgress Progress;
|
||||
|
||||
protected:
|
||||
|
||||
TArray<TSoftObjectPtr<UObject>> SoftAssets;
|
||||
TSharedPtr<FStreamableHandle> StreamableHandle;
|
||||
|
||||
/* Whether the task has already completed, guarding against a second broadcast. */
|
||||
bool bHasCompleted = false;
|
||||
|
||||
void OnLoaded();
|
||||
void OnUpdate(TSharedRef<FStreamableHandle> Handle);
|
||||
};
|
||||
@@ -0,0 +1,136 @@
|
||||
// Copyright (c) 2026 Unreal Directive. Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/HitResult.h"
|
||||
#include "DirectiveUtilTask_AsyncTrace.generated.h"
|
||||
|
||||
struct FTraceHandle;
|
||||
struct FTraceDatum;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncTraceCompleted, const TArray<FHitResult>&, Hits);
|
||||
|
||||
/** The collision shape used by an async trace. */
|
||||
enum class EDirectiveUtilTraceShape : uint8
|
||||
{
|
||||
Line,
|
||||
Sphere,
|
||||
Box,
|
||||
Capsule,
|
||||
};
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_AsyncTrace
|
||||
* Queues a collision trace and broadcasts the hit results on the next tick.
|
||||
* The trace cannot be cancelled.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Trace"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_AsyncTrace : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Performs an asynchronous line trace against the given trace channel.
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Start The start of the trace.
|
||||
* @param End The end of the trace.
|
||||
* @param TraceChannel The trace channel to test against.
|
||||
* @param bMultiTrace If true, returns all hits up to and including the first blocking hit; otherwise returns only the first blocking hit.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Collision",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Line Trace By Channel"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncTrace* AsyncLineTraceByChannel(UObject* WorldContextObject, const FVector Start, const FVector End, const ETraceTypeQuery TraceChannel, const bool bMultiTrace = false);
|
||||
|
||||
/**
|
||||
* Performs an asynchronous sphere sweep against the given trace channel.
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Start The start of the sweep.
|
||||
* @param End The end of the sweep.
|
||||
* @param Radius The radius of the sphere.
|
||||
* @param TraceChannel The trace channel to test against.
|
||||
* @param bMultiTrace If true, returns all hits up to and including the first blocking hit; otherwise returns only the first blocking hit.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Collision",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Sphere Trace By Channel"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncTrace* AsyncSphereTraceByChannel(UObject* WorldContextObject, const FVector Start, const FVector End, const float Radius, const ETraceTypeQuery TraceChannel, const bool bMultiTrace = false);
|
||||
|
||||
/**
|
||||
* Performs an asynchronous box sweep against the given trace channel.
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Start The start of the sweep.
|
||||
* @param End The end of the sweep.
|
||||
* @param HalfSize The half-extents of the box.
|
||||
* @param Orientation The orientation of the box.
|
||||
* @param TraceChannel The trace channel to test against.
|
||||
* @param bMultiTrace If true, returns all hits up to and including the first blocking hit; otherwise returns only the first blocking hit.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Collision",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Box Trace By Channel"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncTrace* AsyncBoxTraceByChannel(UObject* WorldContextObject, const FVector Start, const FVector End, const FVector HalfSize, const FRotator Orientation, const ETraceTypeQuery TraceChannel, const bool bMultiTrace = false);
|
||||
|
||||
/**
|
||||
* Performs an asynchronous capsule sweep against the given trace channel.
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Start The start of the sweep.
|
||||
* @param End The end of the sweep.
|
||||
* @param Radius The radius of the capsule.
|
||||
* @param HalfHeight The half-height of the capsule (including the radius).
|
||||
* @param TraceChannel The trace channel to test against.
|
||||
* @param bMultiTrace If true, returns all hits up to and including the first blocking hit; otherwise returns only the first blocking hit.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Collision",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Capsule Trace By Channel"
|
||||
))
|
||||
static UDirectiveUtilTask_AsyncTrace* AsyncCapsuleTraceByChannel(UObject* WorldContextObject, const FVector Start, const FVector End, const float Radius, const float HalfHeight, const ETraceTypeQuery TraceChannel, const bool bMultiTrace = false);
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
// Called when the trace has completed. Empty if nothing was hit.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncTraceCompleted Completed;
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> WorldContextObject;
|
||||
|
||||
FVector Start = FVector::ZeroVector;
|
||||
FVector End = FVector::ZeroVector;
|
||||
ETraceTypeQuery TraceChannel = ETraceTypeQuery::TraceTypeQuery1;
|
||||
bool bMultiTrace = false;
|
||||
EDirectiveUtilTraceShape Shape = EDirectiveUtilTraceShape::Line;
|
||||
float Radius = 0.0f;
|
||||
float HalfHeight = 0.0f;
|
||||
FVector HalfSize = FVector::ZeroVector;
|
||||
FQuat Orientation = FQuat::Identity;
|
||||
|
||||
void OnTraceComplete(const FTraceHandle& Handle, FTraceDatum& Datum);
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2026 Unreal Directive. Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Engine/TimerHandle.h"
|
||||
#include "DirectiveUtilTask_Delay.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnDelayCompleted);
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_Delay
|
||||
* A cancellable delay that can be ended early by calling EndTask.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Cancellable Delay"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_Delay : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Starts a cancellable delay.
|
||||
* When the delay has completed, the Completed delegate is called.
|
||||
* Call EndTask to cancel the delay before it completes.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Duration The duration of the delay in seconds.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|FlowControl",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Cancellable Delay"
|
||||
))
|
||||
static UDirectiveUtilTask_Delay* CancellableDelay(UObject* WorldContextObject, float Duration);
|
||||
|
||||
/**
|
||||
* Ends the delay early.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|FlowControl")
|
||||
void EndTask();
|
||||
virtual void Activate() override;
|
||||
|
||||
// The delegate called when the delay has completed.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnDelayCompleted Completed;
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> WorldContextObject;
|
||||
|
||||
float Duration = 0.0f;
|
||||
FTimerHandle TimerHandle;
|
||||
|
||||
void OnDelayComplete();
|
||||
};
|
||||
@@ -0,0 +1,181 @@
|
||||
// Copyright (c) 2026 Unreal Directive. Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "GameFramework/Controller.h"
|
||||
#include "DirectiveUtilTask_MoveToLocation.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncMoveToLocation, bool, bSuccess);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAsyncMoveToActor, bool, bSuccess);
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_MoveToLocation
|
||||
* Asynchronously moves an actor to a location.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Move To Location"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_MoveToLocation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Moves the actor to the specified location.
|
||||
* When the movement has succeeded or failed, the Completed delegate is called exactly once with success/failure.
|
||||
* bSuccess is true only when the pawn ends within AcceptanceRadius of Destination; the task also ends
|
||||
* (with the same distance test) when path-following stops for any reason.
|
||||
*
|
||||
* If the controller or pawn is destroyed while moving, the task will automatically end.
|
||||
* If bCheckStuckMovement is enabled and the controller gets stuck while moving, the task will automatically end.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Controller The controller to move.
|
||||
* @param Destination The vector location to move to.
|
||||
* @param AcceptanceRadius The radius around the destination location that is considered acceptable. Be sure to set this to a reasonable value as the controller may never reach the exact destination.
|
||||
* @param bCheckStuckMovement Check if the controller gets stuck while moving.
|
||||
* @param StuckThreshold The distance threshold to consider the controller stuck.
|
||||
* @param bDebugLineTrace Display a line trace to the destination location for a short duration.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Navigation",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Move To Location",
|
||||
AdvancedDisplay=6
|
||||
))
|
||||
static UDirectiveUtilTask_MoveToLocation* MoveToLocation(
|
||||
UObject* WorldContextObject,
|
||||
AController* Controller,
|
||||
FVector Destination,
|
||||
float AcceptanceRadius = 100.0f,
|
||||
bool bCheckStuckMovement = true,
|
||||
float StuckThreshold = 1.0f,
|
||||
bool bDebugLineTrace = false);
|
||||
|
||||
/**
|
||||
* Ends the async action.
|
||||
* This must be called manually when the task is no longer necessary.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|Navigation")
|
||||
void EndTask();
|
||||
virtual void Activate() override;
|
||||
|
||||
// The delegate called when the movement has completed regardless of success. Fires exactly once.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncMoveToLocation Completed;
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
AController* Controller;
|
||||
|
||||
FVector Destination;
|
||||
FVector StartLocation;
|
||||
FVector CurrentLocation;
|
||||
FVector LastCheckedLocation;
|
||||
float AcceptanceRadius = 10.0f;
|
||||
bool bCheckStuckMovement = true;
|
||||
float StuckThreshold = 1.0f;
|
||||
bool bDebugLineTrace;
|
||||
|
||||
FTimerHandle TimerHandle;
|
||||
|
||||
FTimerHandle StuckTimerHandle;
|
||||
|
||||
bool bHasCompleted = false;
|
||||
|
||||
void CheckMoveToLocation();
|
||||
|
||||
void CheckStuckMovement();
|
||||
|
||||
virtual void ExecuteCompleted(bool bSuccess);
|
||||
};
|
||||
|
||||
/**
|
||||
* DirectiveUtilTask_MoveToActor
|
||||
* Asynchronously moves an actor to another actor.
|
||||
*/
|
||||
UCLASS(BlueprintType, meta=(ExposedAsyncProxy = AsyncTask, DisplayName="Async Move To Actor"))
|
||||
class DIRECTIVEUTILITIESRUNTIME_API UDirectiveUtilTask_MoveToActor : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Moves the controller's pawn to the goal actor.
|
||||
* When the movement has succeeded or failed, the Completed delegate is called exactly once with success/failure.
|
||||
* bSuccess is true only when the pawn ends within AcceptanceRadius of the goal actor; the task also ends
|
||||
* (with the same distance test) when path-following stops for any reason. The goal's location is re-read
|
||||
* every poll, so a moving goal is tracked.
|
||||
*
|
||||
* If the controller, pawn, or goal actor is destroyed while moving, the task will automatically end.
|
||||
* If bCheckStuckMovement is enabled and the controller gets stuck while moving, the task will automatically end.
|
||||
*
|
||||
* @param WorldContextObject The world context object.
|
||||
* @param Controller The controller to move.
|
||||
* @param Goal The actor to move to.
|
||||
* @param AcceptanceRadius The radius around the goal actor that is considered acceptable. Be sure to set this to a reasonable value as the controller may never reach the goal's exact location.
|
||||
* @param bCheckStuckMovement Check if the controller gets stuck while moving.
|
||||
* @param StuckThreshold The distance threshold to consider the controller stuck.
|
||||
*/
|
||||
UFUNCTION(
|
||||
BlueprintCallable,
|
||||
meta=(
|
||||
BlueprintInternalUseOnly = "true",
|
||||
Category = "Directive Utilities|Navigation",
|
||||
WorldContext = "WorldContextObject",
|
||||
DisplayName = "Async Move To Actor"
|
||||
))
|
||||
static UDirectiveUtilTask_MoveToActor* MoveToActor(
|
||||
UObject* WorldContextObject,
|
||||
AController* Controller,
|
||||
AActor* Goal,
|
||||
float AcceptanceRadius = 100.0f,
|
||||
bool bCheckStuckMovement = true,
|
||||
float StuckThreshold = 1.0f);
|
||||
|
||||
/**
|
||||
* Ends the async action.
|
||||
* This must be called manually when the task is no longer necessary.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Directive Utilities|Navigation")
|
||||
void EndTask();
|
||||
virtual void Activate() override;
|
||||
|
||||
// The delegate called when the movement has completed regardless of success. Fires exactly once.
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnAsyncMoveToActor Completed;
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
AController* Controller;
|
||||
|
||||
// The cached goal actor; GC nulls it if the actor is destroyed.
|
||||
UPROPERTY()
|
||||
TObjectPtr<AActor> Goal;
|
||||
|
||||
FVector StartLocation;
|
||||
FVector CurrentLocation;
|
||||
FVector LastCheckedLocation;
|
||||
float AcceptanceRadius = 10.0f;
|
||||
bool bCheckStuckMovement = true;
|
||||
float StuckThreshold = 1.0f;
|
||||
|
||||
FTimerHandle TimerHandle;
|
||||
|
||||
FTimerHandle StuckTimerHandle;
|
||||
|
||||
bool bHasCompleted = false;
|
||||
|
||||
void CheckMoveToActor();
|
||||
|
||||
void CheckStuckMovement();
|
||||
|
||||
virtual void ExecuteCompleted(bool bSuccess);
|
||||
};
|
||||
Reference in New Issue
Block a user