Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Custom spline mesh not showing up in game


I am using UE4.10.2 and i recently wanted to learn about spline mesh and how they work. I managed to make them work in blueprint, but i wanted to make splines generated by code in C++ to make tracks. I tried loading a mesh and assigning it to the spline in C++, and the mesh, the spline mesh and the spline itself are showing up in the editor mode. But when i press play the spline mesh is invisible. I tried assigning another mesh to the spline through the menus, and the splinemesh does appear in that case. I don't know what i am doing wrong.

This is the constructor of my spline actor:

      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
     PathSpline = CreateDefaultSubobject<USplineComponent>(TEXT("Path"));
     PathSpline->AttachParent = RootComponent;
     int32 f = 1;
     for (int32 i = 0; i < 10; i++)
         PathSpline->AddSplinePoint(FVector(10*i*100, 10*f*50, i*30), ESplineCoordinateSpace::World);
         f = f*-1;
     NewMeshComponent = NewObject<UStaticMeshComponent>(this, TEXT("Mesh"));
     ConstructorHelpers::FObjectFinder<UStaticMesh> MeshObj(TEXT("/Game/ThirdPerson/Meshes/roadplane.roadplane")); 
     NewMeshComponent->SetWorldScale3D(FVector(10, 10, 1));
     TheMaterial = NewObject<UMaterial>(this, TEXT("Material"));
     static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/ThirdPerson/Meshes/RampMaterial.RampMaterial'"));
     if (MatFinder.Succeeded())
         GEngine->AddOnScreenDebugMessage(1, 14, FColor::Red, "succeeded");
         TheMaterial = MatFinder.Object;
         GEngine->AddOnScreenDebugMessage(1, 14, FColor::Red, "not succeeded");
     TheMaterial->bUsedWithSplineMeshes = true;
     PathSpline->IsVisible = true;

This is the OnConstruction function

 void ASplineTest::OnConstruction(const FTransform & Transform)
     for (int32 i = 0; i < PathSpline->GetNumSplinePoints() - 1; i++)
         USplineMeshComponent* SplineMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), 
         SplineMesh->CreationMethod = EComponentCreationMethod::UserConstructionScript;
         SplineMesh->AttachParent = PathSpline;
         UMaterialInstanceDynamic* dynamicMat = UMaterialInstanceDynamic::Create(TheMaterial, NULL); 
         SplineMesh->SetMaterial(1, dynamicMat); 
         FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
         PathSpline->GetLocalLocationAndTangentAtSplinePoint(i, pointLocationStart, pointTangentStart);
         PathSpline->GetLocalLocationAndTangentAtSplinePoint(i + 1, pointLocationEnd, pointTangentEnd);
         SplineMesh->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);

Here are illustrations to show the problem:

this is the spline mesh with the spline as created and loaded through C++

This is ingame, the spline mesh is not visible

In the editor it is visible ![alt text

I change the splinemesh in the editor menu and it shows in the editor and ingame alt text

Product Version: UE 4.10
dbhdfgh.jpg (44.2 kB)
dfdgsde.jpg (31.9 kB)
dfgsdg.jpg (39.1 kB)
ezezezez.jpg (43.2 kB)
dfgsdg.jpg (39.1 kB)
more ▼

asked Feb 18 '16 at 09:39 AM in C++ Programming

avatar image

46 3 5 7

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Ok i finally fixed it, i had to use an array to store the spline meshes. Now it works

more ▼

answered Feb 18 '16 at 11:30 PM

avatar image

46 3 5 7

avatar image Infiltrator_ Jun 08 '16 at 09:27 PM

Hi Dan, Thanks for sharing this . Could you please share the updated code also ? Thanks Alam.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question