# (Bug?) Spawned Actors Sneaking Out of a TArray in OnConstruction()

**URL:** <https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789>\
**Category:** Mobile\
**Tags:** construction, unreal-engine, editor, UE4, CPP, question\
**Created:** [October 31, 2018, 8:52pm UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789 "2018-10-31T20:52:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SausagesSizzling](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SausagesSizzling](https://forums.unrealengine.com/u/SausagesSizzling)\
**Post date:** [October 31, 2018, 8:52pm UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789/1 "2018-10-31T20:52:06Z")

</div>

I have an ParentActor with a TArray of Actors

```
UPROPERTY(EditAnywhere)
TArray<AExampleActor*> ActorList;

```

I call OnConstruction and everything almost works fine except…

```
void OnConstruction(const FTransform& Transform)
{
	if (GetWorld() && ActorList.Num() == 0)
	{
		for (int Actor= 0; Actor< NumActors; ++Actor)
		{
			FTransform Translation = CalculateTranslation(Actor);
			FTransform SpawnTransform = Transform + Translation;
			AExampleActor* Tile = GetWorld()->SpawnActor<AExampleActor>(SpawnTransform.GetTranslation(), SpawnTransform.GetRotation().Rotator());
			AExampleActor->AttachToActor(this, FAttachmentTransformRules(EAttachmentRule::KeepWorld, false));
			ActorList.Add(Tile);
		}
	}
}

```

I get one group of actors which are connected to the ParentActor as expected but I also get a second group of actors spawning which seem to have forgotten they have any attachment to the Parent . From the debugger it looks like this group is created when I initially click on the ParentActor in the editor but before I have dragged it into the world yet. Is this the expected behaviour?

Thanks

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [October 31, 2018, 9:10pm UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789/2 "2018-10-31T21:10:48Z")

</div>

I’m not sure but I think Actors get garbage-collected if they’re not placed or spawned into the World.

---

<div class="post-metadata">

**Author:** ![NormalNomad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NormalNomad](https://forums.unrealengine.com/u/NormalNomad)\
**Post date:** [January 8, 2019, 8:01pm UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789/3 "2019-01-08T20:01:14Z")

</div>

I have the same issue! Did you figure out the solution?

---

<div class="post-metadata">

**Author:** ![NormalNomad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NormalNomad](https://forums.unrealengine.com/u/NormalNomad)\
**Post date:** [January 9, 2019, 12:07am UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789/4 "2019-01-09T00:07:36Z")

</div>

Check for the transient flag which is set on preview actors. i.e. this-\>HasAnyFlags(EObjectFlags::RF\_Transient)

---

<div class="post-metadata">

**Author:** ![SausagesSizzling](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SausagesSizzling](https://forums.unrealengine.com/u/SausagesSizzling)\
**Post date:** [June 15, 2019, 10:43am UTC](https://forums.unrealengine.com/t/bug-spawned-actors-sneaking-out-of-a-tarray-in-onconstruction/436789/5 "2019-06-15T10:43:19Z")

</div>

Wow this worked, thanks for coming back with an update! How on earth did you figure out this was the issue though?
