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 "Kismet/KismetSystemLibrary.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.
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// Normally, SpawnActor runs the BeginPlay entry point. We
// want to delay that until after we've had a chance to set
// up the TangibleComponent.
params.bDeferConstruction = true;
// Spawn the actor even if it collides with something.
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());
AActor* a = w->SpawnActor(blueprint, &transform, params);
check(a != nullptr);
CurrentActor = a;
// Make sure the label and the name are the same.
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
// because we deferred it in SpawnActor.
a->FinishSpawning(transform, true);
@@ -248,6 +250,18 @@ bool UlxTangible::AnimationStepIsFinished(AActor *target, const FlxAnimationStep
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) {
UlxTangible *tan = GetActorTangibleOrLog(target);
if (tan == nullptr) return TEXT("");

View File

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