Edit:
It properly removes the old meshes when changing any property in the editor (mesh, hiddenInGame, etc), just not when the points are moved.
How can I make that apply to moving the points as well?
That is because you ARE creating (ConstructObject) new SplineMeshComponents every time SetupSpline is called. Normally with Construction Script for Blueprint it would first remove all components that were added previously and then add the new components from executing the Construction Script again.
I don’t know what you need to do in order to trigger this to happen from C++ but here’s a fairly simple alternative solution (not compiled or tested!):
Add this to your ASpline class in the .h
ASpline::ASpline()
{
AddedSplineMeshes.Empty();
}
void ASpline::SetupSpline() {
//Remove existing meshes
for (int32 i = 0; i < AddedSplineMeshes.Num(); i++){
AddedSplineMeshes*->DetachFromParent();
AddedSplineMeshes*->UnregisterComponent();
}
AddedSplineMeshes.Empty();
for (int32 i = 0; i < Spline->GetNumberOfSplinePoints() - 1; i++)
{
USplineMeshComponent* tempMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this);
AddedSplineMeshes.Add(tempMesh);
tempMesh->CreationMethod = EComponentCreationMethod::UserConstructionScript;
tempMesh->SetMobility(EComponentMobility::Static);
tempMesh->AttachParent = Spline;
tempMesh->SetStaticMesh(SplineMesh);
// Code to set curves
tempMesh->RegisterComponent();
}
}
The entire thing disappears when the game runs, no matter what I do.
If I check ‘Hidden in game’, then the shadows immediately disappear in editor, so I know that isn’t the problem since it’s easy to see if that is turned on/off.
Edit2: I didn’t have UPROPERTY() for my array. Adding it made them appear in game too. Thanks!