【问题标题】:unreal engine 4.18.0, Vs2017, Error pointer to incomplete class type is not allowed虚幻引擎 4.18.0,Vs2017,不允许指向不完整类类型的错误指针
【发布时间】:2017-11-01 03:49:26
【问题描述】:

我是 C++ 新手,对 Unreal Engine 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);
}

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

};

【问题讨论】:

    标签: c++ unreal-engine4


    【解决方案1】:

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

    将以下内容添加到 Pickup.cpp:

    #include "Classes/Components/StaticMeshComponent.h"
    

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

    更详细的答案here。检查this reference guide 以了解更改。 SetupAttachment的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-31
      • 2012-08-15
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      相关资源
      最近更新 更多