How to create a cylinder in c++

Hello, I would like to create a cylinder in c++, I can create boxes component and spheres, are there any cyilinder?

Are you talking about static meshes or collision shapes? If the latter then no. There are only spheres, boxes and capsules collision shapes.

How are you creating them?

I have understood, I do it in the blueprint editor.

static mesh

To add a cylinder static mesh:

  #include "Components/StaticMeshComponent.h"
  #include "Engine/StaticMesh.h"

   ...

    UStaticMeshComponent* Cylinder= CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
    Cylinder->SetupAttachment(RootComponent);
    static ConstructorHelpers::FObjectFinder<UStaticMesh> CylinderAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder"));
    if (CylinderAsset.Succeeded())
    {
        Cylinder->SetStaticMesh(CylinderAsset.Object);
        Cylinder->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
        Cylinder->SetWorldScale3D(FVector(1.0f));
    }

Just make sure, you have the starter content directory. Otherwise change the path to your cylinder mesh.

1 Like