How to properly initialize a Custom Actor in C++

teutonicdesign
Fri, 16 Oct 2020 20:29:06 +0000
Asset Creation

Hi community members,

I’m having trouble initializing my custom actor in C++. How do you attach skeletal mesh? The DefaultSceneRoot was also not showing in my BP child class of this actor. Sorry I’m still very new to UE4 C++.

Thanks a lot for helping!

.h

#include "CoreMinimal.h"
#include "Projectile.h"
#include "Arrow.generated.h"

/**
 *
 */
UCLASS()
class RENOVA_API AArrow : public AProjectile
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	AArrow();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	class USkeletalMeshComponent* ArrowMesh;


};

.cpp

#include "Arrow.h"
#include "UObject/ConstructorHelpers.h"
#include "Components/SkeletalMeshComponent.h"

// Sets default values
AArrow::AArrow()
{
	// 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;

	ArrowMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("ArrowMesh"));
	ArrowMesh->SetupAttachment(RootComponent);
	static ConstructorHelpers::FObjectFinder<USkeletalMesh> ArrowMeshAsset(TEXT("/Game/Models/ClassWeapons/arrow_model"));


}

3 posts - 1 participant