AActor *UactorComponent::GetOwner const - 不允许指向不完整类类型的指针 [英] AActor *UactorComponent::GetOwner const - pointer to incomplete class type is not allowed

查看:38
本文介绍了AActor *UactorComponent::GetOwner const - 不允许指向不完整类类型的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 UE4 开发的新手,我已经学习了 Udemy 的虚幻引擎开发课程.我在 Actor 上创建了一个新组件,名为 PositionReporter,标题为 PositionReporter.h

I'm new to UE4 development and I've followed Udemy's Unreal Engine Development course. I have created a new Component on an Actor, named PositionReporter with header PositionReporter.h

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UPositionReporter : public UActorComponent
{
    GENERATED_BODY()

public: 
    // Sets default values for this component's properties
    UPositionReporter();

protected:
    // Called when the game starts
    virtual void BeginPlay() override;

public: 
    // Called every frame
    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

和 PositionReporter.cpp 中的代码

and code in PositionReporter.cpp being

#include "PositionReporter.h"

// Sets default values for this component's properties
UPositionReporter::UPositionReporter()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    PrimaryComponentTick.bCanEverTick = true;

    // ...
}


// Called when the game starts
void UPositionReporter::BeginPlay()
{
    Super::BeginPlay();

    FString t = GetOwner()->GetActorLabel();

    UE_LOG(LogTemp, Warning, TEXT("Position Reporter reporting for duty on %s"), *t);

}


// Called every frame
void UPositionReporter::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    // ...
}

如您所见,我现在正在尝试调用指向通过 GetObject() 检索到的 AActor 的指针上的 GetName 函数.

As you can see, I am now trying to call the GetName function on the Pointer to the AActor retrieved through GetObject().

但是,只要我输入GetObject()->",就不会弹出自动完成功能(就像视频中那样),当我手动添加GetName()"时,我收到编译器错误指向不完整类的指针"类型不允许".

However, as soon as I type "GetObject()->" no autocomplete pops up (as it does in the video) and when I add "GetName()" manually, I get the compiler error "pointer to incomplete class type is not allowed".

做错了什么?我错过了进口吗?我已经将我的代码与 Ben 的 git repo 进行了比较,但找不到任何差异.我使用的是虚幻编辑器 4.16.0!

What am doing wrong? Am I missing an import or so? I already compared my code to Ben's git repo but can't find any differences. I am on unreal editor 4.16.0!

我注意到另一个奇怪的事情:当我从虚幻引擎编辑器编译所有东西时,它编译并运行良好.但是当我用 VS 2017 编译它时,我得到了错误,而且我也没有得到自动完成,这真是令人失望.我错过了什么?

I noticed another strange thing: When I compile everything from Unreal Engine Editor, it compiles and runs fine. But when I compile it with VS 2017 I get the error, and I also dont get the Autocomplete, which is a real bummer. What am I missing?

推荐答案

在 PositionReporter.h 中包含 Engine.h 解决了该问题.

Including Engine.h on PositionReporter.h fixes the issue.

#pragma once

#include "Engine.h" // <- This
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"

您需要给 Intellisense 一些时间...事实上,我关闭并重新打开了解决方案,使其停止显示不存在的错误并提供自动完成功能.

You'll need to give Intellisense some time... As a matter of fact I closed and reopened the solution for it to stop showing the non existing errors and give autocomplete functionality.

注意:正如在其他帖子中提到的,这个解决方案可以很好地实现智能感知自动完成,但并不是最好的,因为它会包含大量内容并大大增加编译时间.包含特定的 .h 文件会更好,但您需要知道要包含什么 .h,而且您可能不知道.

NOTE: As is mentioned in other posts, this solution is good to get intellisense autocompleting but isn't the best as it will include a ton of stuff and greatly increase compilation times. Including the specific .h file would be better, but you need to know what .h to include, and probably you don't know it.

我发现的最佳解决方案是放弃 Intellisense 并使用 Resharper 进行代码自动完成,它运行速度快、自动完成正确并且您不需要包含任何额外的文件.

Best solution I found is ditching Intellisense and use Resharper for code autocompletion, it works fast, autocompletes correctly and you don't need to include any extra file.

这篇关于AActor *UactorComponent::GetOwner const - 不允许指向不完整类类型的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆