SpawnActor spawns permanently

I spawn actors using the following script, and they are successfully created in the level. However, when I stop playing, the avatar actors persist in the level, and new avatars are created on top of them when I play again.


in GE_AvatarManager.h:
    TArray<TSubclassOf<AGE_VATActor>> m_avatarClasses;

UGE_AvatarManager::UGE_AvatarManager()
{
	int maxAvatarIndex = AVATAR::TOTAL_NUMBER_OF_MALE_AVATARS + AVATAR::TOTAL_NUMBER_OF_FEMALE_AVATARS;
	for (int avatarIndex = 1; avatarIndex <= maxAvatarIndex; avatarIndex++)
	{
		FString avatarPathName("BP_Avatar_");
		avatarPathName += FString::FromInt(avatarIndex);
		ConstructorHelpers::FClassFinder<AGE_VATActor> classFinder(*(FString("/Game/Blueprints/Actors/Avatars/") + avatarPathName));

		if (classFinder.Succeeded())
		{
			m_avatarClasses.Add(classFinder.Class);
		}
	}

	UGE_LevelManager::OnSeatsArePlaced.AddUObject(this, &UGE_AvatarManager::OnLevelManagerPlacedSeats);
}

void UGE_AvatarManager::OnLevelManagerPlacedSeats(const TArray<AActor*>& seatActors)
{
	PlaceAvatars(seatActors);
}

void UGE_AvatarManager::PlaceAvatars(const TArray<AActor*>& seatActors)
{
	UWorld* world = GetWorld();

	if (!world)
	{
		return;
	}

	int seatActorCount = seatActors.Num();

	for (int seatIndex = 0; seatIndex < seatActorCount; seatIndex++)
	{
		AActor* seatActor = seatActors[seatIndex];

		int randomAvatarIndex = FMath::RandRange(AVATAR::MIN_AVATAR_INDEX, AVATAR::TOTAL_NUMBER_OF_MALE_AVATARS + AVATAR::TOTAL_NUMBER_OF_FEMALE_AVATARS) - 1;

		AGE_VATActor* spawnedAvatar = world->SpawnActor<AGE_VATActor>(
			m_avatarClasses[randomAvatarIndex],
			seatActor->GetActorLocation() + AVATAR::PLACEMENT_POSITION_OFFSET,
			seatActor->GetActorRotation() + AVATAR::PLACEMENT_ROTATION_OFFSET);

		m_avatarActors.Add(spawnedAvatar);
		m_spawnedAvatarCount++;
	}
}

Before:

After:

Up. Any help will be appreciated.

Are you using level streaming ?

Sounds like you are spawning actors in the persistent level, rather than in the streamed level, so they are not automatically unloaded with level.

Use a SpawnActor variant where you can specify an Owner actor, and pass an actor that is part of the streamed level as owner. Engine should automatically assign the spawned actors to the same level as their owner.

Owner can be specified via the FActorSpawnParameters struct argument.