编译C 电池收集器教程的错误

Compile errors for C++ Battery Collector tutorial

本文关键字:教程 错误 收集器 编译      更新时间:2023-10-16

对不起,非常菜鸟问题,我一直在通过Unreal的C 电池收集器教程进行工作,并且我在教程中对代码有一些编译。

我已经在Visual Studio中进行了关注,在标题文件中创建访问者方法时,我使用Intelli Sense生成了Corossonding类。

Pickup.h

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
UCLASS()
class BATTERYCOLLECTOR_API APickup : public AActor
{
    GENERATED_BODY()
public: 
    // Sets default values for this actor's properties
    APickup();
    // Called every frame
    virtual void Tick(float DeltaTime) override;
    // Return the mesh for the pickup
    FORCEINLINE class UStaticMeshComponent* GetMesh() const { return PickupMesh; }
    // Return whether or not the pickup is active
    UFUNCTION(BlueprintPure, Category = "Pickup");  // <--- error in this line
    bool IsActive();
    // Allows other classes to safely change whether or not the pickup is active 
    UFUNCTION(BlueprintCallable, Category = "Pickup");
    void setActive(bool NewPickupState);
protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
    //True when the pickup can be used, and false when pickup is deactivated
    bool bIsActive;
private:
    //Static mesh to represent the pickup in the level
    UPROPERTY(visibleAnywhere, BlueprintReadOnly, Category = "Pickup", meta = (AllowPrivateAccess = "true"))
    class UStaticMeshComponent* PickupMesh;
};

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 = false;
    // All pickups start active
    bIsActive = true;
    // Create the static mesh component
    PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
}
// Called when the game starts or when spawned
void APickup::BeginPlay()
{
    Super::BeginPlay();
}
// Called every frame
void APickup::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
}
// Visual studio created this definition 
//APickup::UFUNCTION(BlueprintPure, Category)
//{
    //What is should go in here?
//}
// Returns active state
bool APickup::IsActive()
{
    return bIsActive;
}
// Changes active state
void APickup::setActive(bool NewPickupState)
{
    bIsActive = NewPickupState;
}

在.cpp文件中添加注释Visual studio created this definition的行上,这是Visual Studio Code添加的定义,但我不确定应该使用的是什么,并且没有此功能就无法编译。(此定义不在教程中,但VS希望我添加它。(

据我所知,我已经定义了这两个ufunctions的方法

D:/Unreal Projects/BatteryCollector/Source/BatteryCollector/Pickup.h(25) : Error: Function return type: Missing variable type

任何人都可以看到我在做错什么或缺少什么?

来自虚幻文档:

UFUNCTION([specifier, specifier, ...], [meta(key=value, key=value, ...)])
ReturnType FunctionName([Parameter, Parameter, ...])

该声明中没有;,很可能是问题。

请注意,在编辑问题的过程中,您还将;添加到其他声明中,但您应该删除两者。

ps:我将其作为答案,希望将半垃圾评论变成有用的东西。我不知道虚幻,也许这个答案是错误的,然后让我知道。