Hi, I’m new to Unreal Engine.
I’m currently working on a project where I’m creating a C++ actor and using code to generate a cylindrical mesh, its skeleton, and then it should deform based on applied weight. The number of bones to create is determined in the editor via UPROPERTY (I attach the code at the end of the message).
In this scenario, would it be preferable to utilize a DynamicMeshComponent, a SkeletonMeshComponent, or perhaps both in some capacity? I’ve had trouble finding a method to create a cylindrical DynamicMeshComponent programmatically, although I’ve successfully generated a cylindrical SkeletalMeshComponent from a staticMesh. However, I’m struggling to create the bones and establish a hierarchy. Despite searching for tutorials, reading guides, and utilizing IntelliSense, I haven’t found a solution.
Do you have any advice?
Thank you.
.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CylinderActor.generated.h"
UCLASS(Blueprintable)
class UEFEM_API ACylinderActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACylinderActor();
UPROPERTY(EditAnywhere, Category = "SkeletonManager")
int numBones;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
class USkeletalMeshComponent* SkeletalMesh;
};
.cpp
#include "CylinderActor.h"
// Sets default values
ACylinderActor::ACylinderActor()
{
PrimaryActorTick.bCanEverTick = true;
// Set up SkeletalMeshComponent
SkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));
RootComponent = SkeletalMesh;
// Set the mesh
static ConstructorHelpers::FObjectFinder<USkeletalMesh> SkeletalMeshAsset(TEXT("/Game/ThirdPerson/Maps/_GENERATED/pieeg/CylinderProva_SkeletalMesh"));
if (SkeletalMeshAsset.Succeeded())
{
SkeletalMesh->SetSkeletalMesh(SkeletalMeshAsset.Object);
}
}
// Called when the game starts or when spawned
void ACylinderActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACylinderActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}