我是C ++的新手,而且还是虚幻引擎4的新手。我正在按照教程简单地旋转用c ++创建的对象。视频似乎有点过时,已有六个月了。在一行中,我在行this->SampleMesh->AttachtoComponent(this->RootComponent);
表示pointer to incomplete class type is not allowed
时收到错误。我一直在寻找方法,但到目前为止还没有运气。如果有人知道更新的方式,甚至是找到最新教程的地方,我将不胜感激。感谢。
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;
};
答案 0 :(得分:0)
我被困在同一个问题上。 Unreal改变了头文件的包含方式。
将以下内容添加到Pickup.cpp:
#include "Classes/Components/StaticMeshComponent.h"
在这种特定情况下,您可以使用SetupAttachment
功能而不是AttachToComponent
更详细的回答here。检查this reference guide有关更改的信息。关于SetupAttachment的信息。