🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Trying to attach Custom Actor Class to my Character in Unreal, SetupAttachment() won't work Please Help! :)

Started by
1 comment, last by DoomOperator 4 years, 4 months ago

SOLVED XD


Looking for a quick simple solution for this problem i'm having. I want to attach a skeletal mesh via a Custom class i made called ArtifactWheel. Here is the Code for my Custom Actor class starting with the header. I tried to use both AttachtoComponent and SetupAttachment () Functions in the constructor of my Characterbase.cpp but neither seem to display in the Unreal Editor. Can someone please tell me what i am doing wrong? or how i can fix this? or how to attach a custom actor class to my character as a component?

I appreciate all the help i can get, Thankyou for your time.

ArtifactWheel.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ArtifactWheel.generated.h"

UCLASS()
class ALLEGORY_API AArtifactWheel : public AActor
{
GENERATED_BODY()
 
public:  
// Sets default values for this actor's properties
AArtifactWheel();

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = ArtifactWheel)
class USkeletalMeshComponent* ArtifactWheelComp;

};

ArtifactWheel.cpp


#include "ArtifactWheel.h"
#include "Components/SkeletalMeshComponent.h"

// Sets default values
AArtifactWheel::AArtifactWheel()
{
 // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

ArtifactWheelComp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("ArtifactWheel"));
RootComponent = ArtifactWheelComp;
}

// Called when the game starts or when spawned
void AArtifactWheel::BeginPlay()
{
Super::BeginPlay();
 
}

// Called every frame
void AArtifactWheel::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

Now My Character class Constructor code.

ACharacterBase::ACharacterBase()
{

ArtifactWheel = CreateDefaultSubobject<AArtifactWheel>(TEXT("ArtifactWheel"));

ArtifactWheel->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, ArmAttachPoint);

}

Advertisement

@doomoperator It might be you want a derive the ArtifactWheel class from UActorComponent and not "A" AActorComponent.

This topic is closed to new replies.

Advertisement