x

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"

Can you give me an example of SplineMeshComponent in C++?

Hi guys, I´m currently stuck at coverting my spline-based road from blueprints to C++. Off course everything is working fine in blueprints already and I was able to spawn the spline from C++. However, there is no Mesh showing in the game world. As examples seem to be very rare, I would welcome any help you can offer :D

What I have done so far:

 if (Mesh)
         SplineMeshComp->SetStaticMesh(Mesh);
         SplineMeshComp->SetStartAndEnd(
             Spline->GetWorldLocationAtDistanceAlongSpline(i*MeshSize),
             Spline->GetWorldDirectionAtDistanceAlongSpline(i*MeshSize),
             Spline->GetWorldLocationAtDistanceAlongSpline(i*MeshSize + MeshSize),
             Spline->GetWorldDirectionAtDistanceAlongSpline(i*MeshSize + MeshSize)*TangentScale);
         if (Material)
         SplineMeshComp->SetMaterial(0,Material);
         SplineMeshComp->RegisterComponent();
         SplineMeshComp->RegisterComponentWithWorld(GetWorld()); //not sure about that line
         SplineMeshComp->AttachTo(Spline);
         
         SplineMeshComp->bCreatedByConstructionScript = true;

Product Version: Not Selected
Tags:
more ▼

asked Feb 17 '15 at 09:49 AM in C++ Programming

avatar image

potatojoe
257 17 9 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Here is how I do it :

 void ARaceSpline::OnConstruction(const FTransform& Transform)
 {
     for (int32 i = 0; i < mSplineComponent->GetNumSplinePoints() - 1; i++)
     {
         USplineMeshComponent* SplineMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this);
 
         SplineMesh->bCreatedByConstructionScript = true;
         SplineMesh->SetMobility(EComponentMobility::Movable);
         SplineMesh->AttachParent = mSplineComponent;
 
         //Set the color!
         UMaterialInstanceDynamic* dynamicMat = UMaterialInstanceDynamic::Create(mSplineMeshMaterial, NULL);
         dynamicMat->SetVectorParameterValue(TEXT("Color"), FLinearColor(mSegments[i].mColor));
 
         SplineMesh->bCastDynamicShadow = false;
         SplineMesh->SetStaticMesh(mGridMesh);
         SplineMesh->SetMaterial(0, dynamicMat);
 
         //Width of the mesh 
         SplineMesh->SetStartScale(FVector2D(50, 50));
         SplineMesh->SetEndScale(FVector2D(50, 50));
         
         FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
         mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i, pointLocationStart, pointTangentStart);
         mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i + 1, pointLocationEnd, pointTangentEnd);
 
         SplineMesh->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);
     }
 
     RegisterAllComponents();
 }


What seems to be missing in your case is the actual SplineMesh Component creation. Hope this code helps you :)

more ▼

answered Feb 18 '15 at 12:03 AM

avatar image

MickD777
2.1k 70 38 259

avatar image potatojoe Feb 18 '15 at 09:41 AM

Thank you very much!

avatar image shpen Mar 12 '15 at 12:31 AM

bCreatedByConstructionScript is now deprecated. Even if I try to set it to true, my meshes are not deleted on a new construction, so I am left with hundreds of meshes when I move my spline around. How do I fix this?

Edit: Actually, I found your other post at:

https://answers.unrealengine.com/questions/188898/how-can-i-add-components-in-the-onconstruction-fun.html

Thanks!

avatar image MickD777 Mar 12 '15 at 01:42 AM

It's weird that you commenting here actually remove the accepted answer :S I wonder if Epic could change that so we don't actually lose Karma when this happens :S

Anyway, glad you found your answer.

avatar image shpen Mar 13 '15 at 03:02 AM

I hope you don't mind me commenting again. I have a new issue, regarding collisions, specifically that they only work in-editor and not in an exported Windows or Android build. I am not sure how to contact you through the answer hub, but if you could message me on the forums, I would greatly appreciate any assistance you can offer. Thanks!

https://forums.unrealengine.com/member.php?32254-shpen

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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