Preview BP when spawned from component

Hi,

I have a question similar to this: Is there a way to show a dynamic preview mesh in the level viewport?

But this time my “Spawner” is not an actor itself, but just a component which spawns a new Actor during BeginPlay. It’s used for putting items on a vehicle, which the player then can later pick up or return to.

This works fine as it is, but I really want to have a preview of the BP I’m going to spawn or else the positioning of the spawners will be a nightmare.

Any ideas?

Well, you could spawn the actors in the construction script by moving these nodes into a function and calling it, but that would be inefficient, as the actors would respawn every time you do anything in the editor. It would be a better idea to visualize the location with DrawDebugSphere or something similar in your Construction Script.

“Solved” it, for anyone who is interested:

I added an “InitPreview” method in C++ which is called in the ConstructionScript. This is surrounded by #if WITH_EDITOR.

	// create preview component
	if (ItemToSpawn)
	{
		AActor* Owner = GetOwner();
		check(Owner);
		
		UChildActorComponent* PreviewCmp = GetChildComponentByClass<UChildActorComponent>(this);
		if (!PreviewCmp)
		{
			PreviewCmp = Cast<UChildActorComponent>(Owner->AddComponentByClass(UChildActorComponent::StaticClass(), true, FTransform::Identity, false));
			if (PreviewCmp)
			{
				PreviewCmp->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetIncludingScale);
				PreviewCmp->bIsEditorOnly = true;
				PreviewCmp->SetHiddenInGame(true);
			}
		}
		if (PreviewCmp)
		{
			PreviewCmp->SetChildActorClass(ItemToSpawn);
		}
	}

In BeginPlayI destroy the ChildActorComponent. It works