I’m new to C++, and newer still to Unreal Engine 4. I’m following a video tutorial to simply rotate an object created with c++. The video appears to be somewhat out of date, being six months old. On one line I get an error with the line this->SampleMesh->AttachtoComponent(this->RootComponent); stating pointer to incomplete class type is not allowed. I’ve searched for ways around it, but have had no luck so far. If anyone knows the updated way to do this, I would be grateful. Thanks.
Pickup.cpp
#include "Pickup.h"
// Sets default values
APickup::APickup()
{
// 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;
SampleMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SampleMesh"));
this->SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
this->RootComponent = SceneComponent;
this->SampleMesh->AttachtoComponent(this->RootComponent);
this->RotationRate = FRotator(0.0f, 180.0f, 0.0f);
this->Speed = 1.0f;
}
// Called when the game starts or when spawned
void APickup::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
this->AddActorLocalRotation(this->RotationRate * DeltaTime * Speed);
}
Pickup.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
UCLASS()
class LEARNAGAIN_API APickup : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APickup();
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, BluePrintReadWrite, Category = Pickup)
UStaticMeshComponent* SampleMesh;
UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
FRotator RotationRate;
UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
USceneComponent* SceneComponent;
UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = Pickup)
float Speed;
};