虚幻引擎 4.18.0,VS2017,不允许指向不完整类类型的错误指针



我是C++新手,对虚幻引擎4还是新手。我正在按照教程简单地旋转使用 c++ 创建的对象。该视频似乎有些过时,已有六个月的历史。在一行上,我收到错误,该行this->SampleMesh->AttachtoComponent(this->RootComponent);说明pointer to incomplete class type is not allowed.我一直在寻找解决方法,但到目前为止还没有运气。 如果有人知道执行此操作的更新方法,甚至是查找最新教程的地方,我将不胜感激。谢谢。

皮卡.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);
}

皮卡.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;
};

我被困在同一个问题上。虚幻引擎改变了头文件的包含方式。

将包含的以下内容添加到取件.cpp:

#include "Classes/Components/StaticMeshComponent.h"

在这种特定情况下,您可以使用SetupAttachment函数而不是AttachToComponent

更详细的答案在这里。有关更改,请查看此参考指南。有关安装附件的信息。

最新更新