I am working on a prototype for my senior capstone class and I was trying to develop a tool to allow a designer to quickly create a procedurally generated race car track. This all works very well in the editor, but none of the spline mesh components seem to be showing up in a packaged build of the game which is obviously a pretty big issue. There seems to be no presence of either the mesh or any of it’s collisions. Here is what some of my code looks like:
Here I am creating the pieces of the track with a for loop that scans through a spline created by the tool.
void ATrackGenerator::BuildTrack(UStaticMesh* trackElementMesh)
{
print_num(NumSplinePoints);
for (int32 i = 0; i < NumSplinePoints - 1; i++)
{
SplineMeshConstruct.Add(BuildTrackElement(trackElementMesh, i));
}
RegisterAllComponents();
}
USplineMeshComponent* ATrackGenerator::BuildTrackElement(UStaticMesh* trackElementMesh, int32 loopIndex)
{
// Gather Data for element build
if (loopIndex + 1 >= NumSplinePoints)
return nullptr;
int32 localCurrentLoopIndex = loopIndex;
int32 localNextLoopIndex = loopIndex + 1;
UStaticMesh* localTrackElementMesh = trackElementMesh;
FVector localStartLocation;
FVector localStartTangent;
SplineComponent->GetLocalLocationAndTangentAtSplinePoint(localCurrentLoopIndex, localStartLocation, localStartTangent);
FVector localEndLocation;
FVector localEndTangent;
SplineComponent->GetLocalLocationAndTangentAtSplinePoint(localNextLoopIndex, localEndLocation, localEndTangent);
//Create spline mesh component
USplineMeshComponent* splineMeshComponent = NewObject<USplineMeshComponent>(this, USplineMeshComponent::StaticClass());
splineMeshComponent->CreationMethod = EComponentCreationMethod::UserConstructionScript;
splineMeshComponent->SetMobility(EComponentMobility::Movable);
splineMeshComponent->AttachParent = SplineComponent;
splineMeshComponent->SetStaticMesh(trackElementMesh);
splineMeshComponent->SetStartAndEnd(localStartLocation, localStartTangent, localEndLocation, localEndTangent);
splineMeshComponent->SetStartScale(FVector2D(RoadConstruct[loopIndex].TrackWidth, RoadConstruct[loopIndex].TrackThickness));
splineMeshComponent->SetEndScale(FVector2D(RoadConstruct[loopIndex].TrackWidth, RoadConstruct[loopIndex].TrackThickness));
return splineMeshComponent;
}
In the Editor it looks like this:
In the packaged build it looks like this: