Refactor tangible construction to use a pre-spawn initializer. This makes it so that the tangible is usable during ActorComponent initialization.
This commit is contained in:
@@ -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<UlxTangibleComponent>(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) {
|
||||
|
||||
Reference in New Issue
Block a user