Reputation: 11
I'm new to C++, and newer still to Unreal Engine 4. I'm following a 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, or even a place to find up to date tutorials, 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->SampleMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
//this->SampleMesh->AttachtoComponent(this->RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
//this->SampleMesh->AttachtoComponent(this->SceneComponent);
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;
};
Upvotes: 1
Views: 1249
Reputation: 21
I was stuck on the same issue. Unreal has changed how header files are included.
Add the following included to Pickup.cpp:
#include "Classes/Components/StaticMeshComponent.h"
and in this specific case you can use the SetupAttachment
function rather than AttachToComponent
More detailed answer here. Check this reference guide about the changes. Info on SetupAttachment.
Upvotes: 2