From 0a3a7b9a62084fe7feb96975a910879dbf505b3a Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 15 Oct 2025 18:41:16 -0400 Subject: [PATCH] Refactor tangible construction to use a pre-spawn initializer. This makes it so that the tangible is usable during ActorComponent initialization. --- Source/Integration/Tangible.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/Integration/Tangible.cpp b/Source/Integration/Tangible.cpp index 0d7005e6..16d4b369 100644 --- a/Source/Integration/Tangible.cpp +++ b/Source/Integration/Tangible.cpp @@ -91,29 +91,27 @@ void UlxTangible::SetActorBlueprint(const FString &XName) { // Spawn the actor even if it collides with something. params.bNoFail = true; - params.bDeferConstruction = true; + params.bDeferConstruction = false; - // This pre-spawn initialization will inject the tangible component into the actor. - UlxTangible *ThisTangible = this; - params.CustomPreSpawnInitalization = [ThisTangible](AActor* A) + // This pre-spawn initialization will finish setting up the actor before + // the beginplay entry points run. This is called by 'SpawnActor', below. + // + params.CustomPreSpawnInitalization = [&](AActor* A) { + // Inject the tangible component into the actor. UActorComponent* ac = A->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false); UlxTangibleComponent* tc = Cast(ac); check(tc != nullptr); - tc->Tangible = ThisTangible; + tc->Tangible = this; + + // Make sure the actor label matches the actor name. + A->SetActorLabel(params.Name.ToString()); }; 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()); - - // This executes the BeginPlay entry point. We have to do this here - // because we deferred it in SpawnActor. - a->FinishSpawning(transform, true); } void UlxTangible::UpdateAnimationQueue(std::string_view aq) {