How to properly initialize a Custom Actor in C++

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"));


}

Try typing:

UPROPERTY()

class USkeletalMeshComponent* ArrowMesh;

into the header class somewhere.

If that doesn’t fix it, then I’m not sure what the problem could be.

Thanks! I think what I need was also included in this doc. Just didn’t know that you need to create an object such as sphere component and set “RootComponent = SphereComponent” :slight_smile:
https://docs.unrealengine.com/en-US/Programming/Tutorials/Components/1/index.html