More refactoring of scripted animations: Tangibles now contain ScriptedAnimation pointers.

This commit is contained in:
2025-10-15 18:08:30 -04:00
parent fbe2b7a45a
commit 23d8e8684d
5 changed files with 46 additions and 21 deletions

Binary file not shown.

View File

@@ -1,3 +1,6 @@
#pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
// #include "Kismet/KismetSystemLibrary.h" // #include "Kismet/KismetSystemLibrary.h"
// #include "CommonTypes.h" // #include "CommonTypes.h"

View File

@@ -89,26 +89,28 @@ void UlxTangible::SetActorBlueprint(const FString &XName) {
// Create the actor at the specified location even if there's something in the way. // Create the actor at the specified location even if there's something in the way.
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// Normally, SpawnActor runs the BeginPlay entry point. We // Spawn the actor even if it collides with something.
// want to delay that until after we've had a chance to set
// up the TangibleComponent.
params.bDeferConstruction = true;
params.bNoFail = true; params.bNoFail = true;
params.bDeferConstruction = true;
// This pre-spawn initialization will inject the tangible component into the actor.
UlxTangible *ThisTangible = this;
params.CustomPreSpawnInitalization = [ThisTangible](AActor* A)
{
UActorComponent* ac = A->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
check(tc != nullptr);
tc->Tangible = ThisTangible;
};
UE_LOG(LogLuprexIntegration, Display, TEXT("Creating Actor: %s"), *params.Name.ToString()); UE_LOG(LogLuprexIntegration, Display, TEXT("Creating Actor: %s"), *params.Name.ToString());
AActor* a = w->SpawnActor(blueprint, &transform, params); AActor* a = w->SpawnActor(blueprint, &transform, params);
check(a != nullptr); check(a != nullptr);
CurrentActor = a;
// Make sure the label and the name are the same. // Make sure the label and the name are the same.
a->SetActorLabel(params.Name.ToString()); a->SetActorLabel(params.Name.ToString());
// Insert a TangibleComponent into the actor.
// Link the actor to its tangible, and the tangible to its actor.
UActorComponent* ac = a->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
check(tc != nullptr);
tc->Tangible = this;
CurrentActor = a;
// This executes the BeginPlay entry point. We have to do this here // This executes the BeginPlay entry point. We have to do this here
// because we deferred it in SpawnActor. // because we deferred it in SpawnActor.
a->FinishSpawning(transform, true); a->FinishSpawning(transform, true);
@@ -248,6 +250,18 @@ bool UlxTangible::AnimationStepIsFinished(AActor *target, const FlxAnimationStep
return tan->AnimTracker.IsFinished(step.Hash); return tan->AnimTracker.IsFinished(step.Hash);
} }
UlxScriptedAnimations *UlxTangible::GetScriptedAnimations(AActor *Target)
{
UlxTangible *tan = GetActorTangibleOrLog(Target);
if (tan == nullptr) return nullptr;
if (tan->ScriptedAnimations == nullptr)
{
tan->ScriptedAnimations = NewObject<UlxScriptedAnimations>();
}
return tan->ScriptedAnimations;
}
FString UlxTangible::GetTangiblePlane(AActor* target) { FString UlxTangible::GetTangiblePlane(AActor* target) {
UlxTangible *tan = GetActorTangibleOrLog(target); UlxTangible *tan = GetActorTangibleOrLog(target);
if (tan == nullptr) return TEXT(""); if (tan == nullptr) return TEXT("");

View File

@@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "AnimQueue.h" #include "AnimQueue.h"
#include "ScriptedAnimation.h"
#include "Tangible.generated.h" #include "Tangible.generated.h"
@@ -45,7 +46,7 @@ public:
// The tangible ID. // The tangible ID.
UPROPERTY() UPROPERTY()
uint64 TangibleId; uint64 TangibleId = 0;
UPROPERTY() UPROPERTY()
TWeakObjectPtr<AActor> CurrentActor; TWeakObjectPtr<AActor> CurrentActor;
@@ -54,23 +55,27 @@ public:
UPROPERTY() UPROPERTY()
FString ActorBlueprintName; FString ActorBlueprintName;
// This is
UPROPERTY()
UlxScriptedAnimations *ScriptedAnimations = nullptr;
// Animation tracker // Animation tracker
FlxAnimTracker AnimTracker; FlxAnimTracker AnimTracker;
// Animation that is waiting to be finished. // Animation that is waiting to be finished.
uint64 PendingAnimationHash; uint64 PendingAnimationHash = 0;
// When do we timeout the pending animation. // When do we timeout the pending animation.
double PendingAnimationTimeout; double PendingAnimationTimeout = 0.0;
// Current Plane. // Current Plane.
FName Plane; FName Plane;
// True if luprex thinks this object is Near the player. // True if luprex thinks this object is Near the player.
bool NearAccordingToLuprex; bool NearAccordingToLuprex = false;
// True if unreal thinks this object is Near the player. // True if unreal thinks this object is Near the player.
bool NearAccordingToUnreal; bool NearAccordingToUnreal = false;
// Delete the current actor. // Delete the current actor.
// //
@@ -157,6 +162,9 @@ public:
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "Target", ExpandBoolAsExecs="ReturnValue"), Category = "Luprex|Animation Queue") UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "Target", ExpandBoolAsExecs="ReturnValue"), Category = "Luprex|Animation Queue")
static bool AnimationStepIsFinished(AActor *Target, const FlxAnimationStep &Step); static bool AnimationStepIsFinished(AActor *Target, const FlxAnimationStep &Step);
UFUNCTION(BlueprintPure, Meta = (DefaultToSelf = "Target"), Category = "Luprex|Scripted Animations")
static UlxScriptedAnimations *GetScriptedAnimations(AActor *Target);
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Tangible") UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Tangible")
static FString GetTangiblePlane(AActor* target); static FString GetTangiblePlane(AActor* target);