Why doesn't my USplineMeshComponent have a material?

I’m playing around with understanding how splines work, and I’m creating a number of USplineMeshComponents during runtime. No matter what I do, however, I cannot get my components to show up with the default material for the StaticMesh I’m using - they all use the default WorldGridMaterial.

If I swap to using a UStaticMeshComponent it shows up fine, but I obviously lose the ability to skew the mesh based on the spline’s path, so I can’t use that.

I’ve pasted a simple example below that I think reproduces the problem in 4.24 (I haven’t tested in 4.25 yet). Just drag an instance of the actor into a level and choose any Static Mesh for the Mesh property.

Any suggestions as to what I might be missing is greatly appreciated!

DeleteMeActor.h

#pragma once

#include "CoreMinimal.h"
#include "Components/SplineMeshComponent.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/Actor.h"
#include "DeleteMeActor.generated.h"

UCLASS()
class TESTGAME_API ADeleteMeActor : public AActor
{
    GENERATED_BODY()

public:	
    ADeleteMeActor();

protected:
    virtual void BeginPlay() override;

private:
    UPROPERTY(EditAnywhere)
    UStaticMesh* Mesh;
};

DeleteMeActor.cpp

#include "DeleteMeActor.h"

ADeleteMeActor::ADeleteMeActor()
{
    if (!RootComponent)
    {
        RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    }
}

void ADeleteMeActor::BeginPlay()
{
    Super::BeginPlay();

    // UStaticMeshComponent* MeshComponent = NewObject<UStaticMeshComponent>(this);
    USplineMeshComponent* MeshComponent = NewObject<USplineMeshComponent>(this);
    MeshComponent->SetMobility(EComponentMobility::Movable);
    MeshComponent->SetStaticMesh(Mesh);

    MeshComponent->SetCollisionEnabled(ECollisionEnabled::Type::QueryAndPhysics);
    MeshComponent->RegisterComponent();
    MeshComponent->AttachToComponent(
            RootComponent,
            FAttachmentTransformRules::KeepRelativeTransform
    );
}
1 Like

I found the solution in https://answers.unrealengine.com/questions/954199/view.html. A material has a checkbox in the material editor called “Used with Spline Meshes”, which needs to be checked.

I wish the engine emitted a warning if one tried to use a material for something it’s not meant for.

2 Likes

Thanks for sharing!! :slight_smile:

When simple make it complicated… :wink:

1 Like