I have been working on spawning splinemeshcomponent through c++
But I don’t see them working.
This is what I am doing
.h
/** Spline component responsible for creating the ring structure */
UPROPERTY()
TSubobjectPtr<USplineComponent> SplineComp;
/** Array to store mesh components */
UPROPERTY()
TSubobjectPtr<USplineMeshComponent> SplineMeshArray[12];
And the cpp file
APlanetActor::APlanetActor(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
SplineComp = PCIP.CreateDefaultSubobject<USplineComponent>(this, TEXT("SplineComp1"));
for (int32 i = 0; i < 12; i++)
{
FString TheName = "Splinemesh" + FString::FromInt(i);
SplineMeshArray[i] = PCIP.CreateDefaultSubobject<USplineMeshComponent>(this, FName(*TheName));
SplineMeshArray[i]->SetStaticMesh(SplineStaticMesh);
SplineMeshArray[i]->ForwardAxis = ESplineMeshAxis::Y;
}
}
After setting the values of the splinecomponent,
I set the values of splinemeshcomponent a bit after the actor has been spawned
for (int32 i = 0; i < 11; i++)
{
FVector StartLocation, StartTangent, EndLocation, EndTangent;
SplineComp->GetLocalLocationAndTangentAtSplinePoint(i, StartLocation, StartTangent);
SplineComp->GetLocalLocationAndTangentAtSplinePoint((i + 1), EndLocation, EndTangent);
SplineMeshArray[i]->SetStartAndEnd(StartLocation, StartTangent, EndLocation, EndTangent);
FVector Location = SplineMeshArray[i]->GetStartPosition();
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, FString::SanitizeFloat(Location.X) + " " + FString::SanitizeFloat(Location.Y) + " " + FString::SanitizeFloat(Location.Z));
}
The GEngine shows the location of all the spline mesh but, I can’t see the mesh at all. The code is executed a bit after beginplay.