# Preview BP when spawned from component

**URL:** <https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514>\
**Category:** Editor Scripting\
**Tags:** unreal-engine, question\
**Created:** [November 25, 2024, 4:42pm UTC](https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514 "2024-11-25T16:42:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [November 25, 2024, 4:42pm UTC](https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514/1 "2024-11-25T16:42:48Z")

</div>

Hi,

I have a question similar to this: [Is there a way to show a dynamic preview mesh in the level viewport?](https://forums.unrealengine.com/t/is-there-a-way-to-show-a-dynamic-preview-mesh-in-the-level-viewport/753072)

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.

 ![grafik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/5/52579406178307763adc525e96391597599c047a.png)

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?

---

<div class="post-metadata">

**Author:** ![jmancoder](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jmancoder/32/943721_2.png) [@jmancoder](https://forums.unrealengine.com/u/jmancoder)\
**Post date:** [November 25, 2024, 6:15pm UTC](https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514/2 "2024-11-25T18:15:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [December 20, 2024, 9:35am UTC](https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514/3 "2024-12-20T09:35:02Z")

</div>

“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`.

```auto
	// 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 `BeginPlay`I destroy the `ChildActorComponent`. It works

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [January 19, 2025, 9:35am UTC](https://forums.unrealengine.com/t/preview-bp-when-spawned-from-component/2150514/4 "2025-01-19T09:35:43Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
