I use USplineComponent to generate a mesh along the spline. After receiving very weired output meshes I checked if USplineComponent contains any points after instantiating the object. And indeed, it did! Can anybody explain why? I don’t like it.
Hey padmalcom-
Can you explain what you’re trying to do and show the setup you’re using? By default a spline will have a minimum of two points (the beginning and end). If possible can you provide a sample project with the issue you’re seeing or provide steps that I can follow to setup the same thing on my end?
Cheers
Hey ,
I’m simply creating a USplineComponent object that I use to generate a street mesh along it by using UProceduralMeshComponent. That works pretty good in 4.10.1 but what I do not understand is why a USplineComponent has two points directly after the object creation. I mean I want to set start and endpoint myself. Instead it seems to be set to some default points. Just try:
USplineComponent* spline = ObjectInitializer.CreateDefaultSubobject<USplineComponent>(this, TEXT("StreetSpline"));
UE_LOG(LogTemp, Warning, TEXT("Spline has %d points"), this->spline->GetNumSplinePoints());
this->spline->ClearSplinePoints();
UE_LOG(LogTemp, Warning, TEXT("Spline now has %d points"), this->spline->GetNumSplinePoints());
The first log will show that a new spline has 2 points, a cleared one has 0 (As I’d expect it to be for a fresh object).
I don’t think it is a bug but it should at least be documented somewhere?
For me to test on my end can you elaborate on where this code needs to be added? Is this inside a custom actor class/game mode/ etc? Additionally, if you’re adding this to a custom function, does the function have any other code than this and how is the function being called? If possible, please list the steps you used in your setup so that I can try to match your case as closely as possible.
Yes, I created a custom actor and withing its constructor I call the code. Here is the entire instantiation:
AProceduralStreetActor::AProceduralStreetActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
UE_LOG(LogTemp, Warning, TEXT("Constructing a procedural mesh actor."));
this->spline = ObjectInitializer.CreateDefaultSubobject<USplineComponent>(this, TEXT("StreetSpline"));
this->spline->ClearSplinePoints();
mesh = ObjectInitializer.CreateDefaultSubobject<UProceduralMeshComponent>(this, TEXT("Procedural Building"));
RootComponent = mesh;
this->spline->AttachParent = mesh;
}
I’m not sure I’m seeing what you’re referring to. I entered the code you provided into the constructor of an Actor class. When I played in the editor the output log showed that the spline was created with 2 points by default but after the call to ClearSplinePoints() it then printed that there were 0 points. Can you explain exactly what is wrong?
There is nothing wrong. I just wanted to know if there is a reason why the spline contains two default points that are deleted anyway after creating an instance of the spline class. It took me some time to figure out why my spline did not look as I expected it to do since it is not documented that a spline contains 2 points per default.
The two default points represent the starting / ending points of the spline itself. As other points are added to the spline (to make it bend/curve if needed) the number of points will increase. Calling ClearSplinePoints() will then remove the points along the spline.