Spline Meshes don't bend smoothly.

Hey! I tried to make a something like road. And I want to controll the number my texture will be repeated on this road. It would be perfect if every cell (I call a part of the road with 1 texture repeating “cell”) will be a separate mesh ot manipulate his location or texture color. Picture 1 shows how I did it in Unity. Also I want to set one texture for face part of my meshes and another textur for sides. I guess I need sockets for this but I don’t know how to specify it for mesh I created with UE Modeling.

I tried to use USplineMeshComponent and I was looking for a lot of ways to get what I want, but it still doesn’t work. I figured out that when I have few points in the spline my spline meshes don’t bend. In picture 2 it can be seen that in part 1 it’s ok, in part 2 it bend only 1-2 tilmes and in part 3 spline meshes are bended with bugs.

I’ll try to generate a few spline points with code, but it seems to be “not a perfect solution”. How really should I do what I want? Thank you!

Picture 1:

Picture 2: (My current road in wireframe mode)

Pictrue 3: (Current road in lit mode)

Pricture 4: (My Mesh) You might think there are too many vertices, but I already tried with fewer number of vertices, the result the same. But when there only 8 vertices (the simpliest cube) it works, but I need to combine a few meshes into one to make it single mesh and apply texture (material) on it.

My code of spline mesh generation:

for (int i = 0; i < MeshNumber; ++i) {
	if (IsSkipping and i % 2 == 1) {
	    continue;
	}
	const float Time = float(i) / MeshNumber;
	const float NextTime = float(i + 1) / MeshNumber;
	auto NewMesh = NewObject<USplineMeshComponent>(this);
	NewMesh->SetMobility(EComponentMobility::Movable);
	NewMesh->SetStaticMesh(MapMesh);
	// NewMesh->SetWorldRotation(Spline->GetRotationAtTime(Time, ESplineCoordinateSpace::Local, true));
    NewMesh->SetSplineUpDir(Spline->GetDefaultUpVector(ESplineCoordinateSpace::Local));
	
 
	NewMesh->SetStartAndEnd(
		Spline->GetLocationAtTime(Time, ESplineCoordinateSpace::Local, true),
		Spline->GetTangentAtTime(Time, ESplineCoordinateSpace::Local, true),
		Spline->GetLocationAtTime(NextTime, ESplineCoordinateSpace::Local, true),
		Spline->GetTangentAtTime(NextTime, ESplineCoordinateSpace::Local, true)
	);
 
	NewMesh->SetStartScale(MeshScale);
	NewMesh->SetEndScale(MeshScale);

 
	NewMesh->AttachToComponent(Spline, FAttachmentTransformRules::KeepRelativeTransform);
	NewMesh->RegisterComponent();
}
1 Like

Using the following blueprint script I get this result