# Attaching actor to actor in constructor

**URL:** <https://forums.unrealengine.com/t/attaching-actor-to-actor-in-constructor/459244>\
**Category:** Blueprint\
**Tags:** spawn, child-actors, unreal-engine, question\
**Created:** [December 8, 2019, 9:55am UTC](https://forums.unrealengine.com/t/attaching-actor-to-actor-in-constructor/459244 "2019-12-08T09:55:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [December 8, 2019, 9:55am UTC](https://forums.unrealengine.com/t/attaching-actor-to-actor-in-constructor/459244/1 "2019-12-08T09:55:56Z")

</div>

The code in my parent-actor-constructor:

```
	UWorld* world = GetWorld();
	if (world != nullptr)
	{
		FActorSpawnParameters spawnParams;
		spawnParams.Owner = this;
		spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		AC_BoardSpot* newBS = GetWorld()->SpawnActor<AC_BoardSpot>(AC_BoardSpot::StaticClass(), GetTransform(), spawnParams);
		newBS->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform); // <<< problem here
}

```

Error in SceneComponent.cpp when I drag the parent into the level:

```
if (ensureMsgf(AttachParent == nullptr || !AttachParent->AttachChildren.Contains(this), TEXT("SetupAttachment cannot be used once a component has already had AttachTo used to connect it to a parent."))) // UE4Editor-Win64-DebugGame.exe has triggered a breakpoint.

```

Both actors use a dummy root if that matters:

```
// Dummy Root.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(ROOT_NAME));
RootComponent->SetMobility(EComponentMobility::Static);
```

---

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [December 8, 2019, 12:01pm UTC](https://forums.unrealengine.com/t/attaching-actor-to-actor-in-constructor/459244/2 "2019-12-08T12:01:02Z")

</div>

Moving the code to the

```
virtual void OnConstruction(const FTransform& Transform) override;

```

did the trick.
