Hi,
I am trying to make an Actor with a SplineComponent that should add SplineMeshComponents dynamically after editing the spline in editor. But it results in TRASH objects all the time! Basically I have the same setup as in this three year old code. I tried with the root component mobility static and without:
.h:
UPROPERTY()
USplineComponent* WaySpline;
/** Internal book keeping for the spline meshes we created along the spline */
UPROPERTY()
TArray<USplineMeshComponent*> SplineMeshComponents;
.cpp:
void ARoad::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
// add missing nummber (just one normally as the construction script should run after each edit in editor)
for (int32 NumToAdd = 0; NumToAdd < (WaySpline->GetNumberOfSplinePoints()-1 - SplineMeshComponents.Num()); NumToAdd++)
{
USplineMeshComponent* SplineMesh = NewObject<USplineMeshComponent>(this);
SplineMesh->CreationMethod = EComponentCreationMethod::UserConstructionScript;
SplineMesh->SetMobility(EComponentMobility::Static);
SplineMesh->SetupAttachment(WaySpline);
SplineMesh->SetStaticMesh(Mesh);
SplineMesh->RegisterComponent();
SplineMesh->UpdateRenderStateAndCollision();
SplineMeshComponents.Add(SplineMesh);
}
}
Adding two objects, they are first named _0 and _1. A second call to OnConstruct follows directly when dragging the actor in the viewport, it has trash objects named _1 and _2.
Am I missing s.th. here??? What is the correct way of adding Components in the construction script? Is it even possible?
Cheers