Components created in "OnConstruction(..)" are deleted when hitting Play

Hey there,

similar to the Spline creation in Blueprints, i create my SplineMeshs along a Spline in my OnConstruction(…) function.
This is working for the part where i can create splines before the game is starting (making the creation of different trees easier).

The problem is, that these Components are all deleted once i start the Game. I can see the actor in the Outliner, but it has no Components (despite the SplineComponent that is created outside of the OnConstruction(…)).

Here is the cpp Code of my Class. Please tell me if i’m missing some function or variable.

// Fill out your copyright notice in the Description page of Project Settings.

#include "UnknownProject.h"
#include "Spawner_Tree.h"

void ASpawner_Tree::OnConstruction(const FTransform & Transform)

	NumberOfSplinePoints = Spline->GetNumSplinePoints();

	// Adding and removing entries in the BranchPointData Array based on the number of spline points
	if (NumberOfSplinePoints > BranchPointData.Num())
		FBranchData TempData;
	else if (NumberOfSplinePoints < BranchPointData.Num())
		BranchPointData.RemoveAt(BranchPointData.Num() - 1);

	// Calling the method to create SplineMeshs along the Spline
	for (int z = 0; z < NumberOfSplinePoints - 1; z++)
		if (z == NumberOfSplinePoints - 2 && bHasEndPoint)
			CreateSplineMesh(z, EndMesh);
			CreateSplineMesh(z, MainMesh);

	// Creating the leafs mesh if the bool is true
	if (bHasLeafs && NumberOfSplinePoints > 0)
		UStaticMeshComponent* TempStaticMesh = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), this);
		TempStaticMesh->SetWorldLocation(Spline->GetWorldLocationAtSplinePoint(NumberOfSplinePoints - 1));
		TempStaticMesh->CreationMethod = EComponentCreationMethod::SimpleConstructionScript;	


void ASpawner_Tree::CreateSplineMesh(int32 _LoopIndex, UStaticMesh* _SplineMesh)
	int32 NextLoopIndex = _LoopIndex + 1;
	FVector CurrentPointPosition, NextPointPosition, CurrentPointTangent, NextPointTangent;
	Spline->GetLocalLocationAndTangentAtSplinePoint(_LoopIndex, CurrentPointPosition, CurrentPointTangent);
	Spline->GetLocalLocationAndTangentAtSplinePoint(NextLoopIndex, NextPointPosition, NextPointTangent);

	FVector2D StartScale, EndScale;
	StartScale.X = BranchPointData[_LoopIndex].PointWidth;
	StartScale.Y = BranchPointData[_LoopIndex].PointHeight;

	if (BranchPointData.IsValidIndex(NextLoopIndex))
		EndScale.X = BranchPointData[NextLoopIndex].PointWidth;
		EndScale.Y = BranchPointData[NextLoopIndex].PointHeight;
	USplineMeshComponent* SplineMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this);
	SplineMesh->AttachParent = Spline;
	SplineMesh->bCastDynamicShadow = true;
	SplineMesh->SetStartAndEnd(CurrentPointPosition, CurrentPointTangent, NextPointPosition, NextPointTangent);
	SplineMesh->CreationMethod = EComponentCreationMethod::UserConstructionScript;
	SplineMesh->ForwardAxis = ESplineMeshAxis::Z;


	Spline = CreateDefaultSubobject<USplineComponent>(FName("Spline"));

	RootComponent = Spline;

	bReplicates = true;

EDIT: The only “workaround” so far is, calling “OnConstruction” in the BeginPlay() again

Hey I seem to have the exact same problem. can be reproduced in 4.8.1 as well. And the issue is also intermittent. Sometimes when hitting play components created within OnConstruction show up when hitting play in the editor but some times they are just deleted ( not visible in viewport ) as soon as I hit play in editor