【发布时间】:2019-07-02 15:32:11
【问题描述】:
抱歉,收到了一个非常菜鸟的问题,我一直在处理来自 Unreal 的 C++ Battery Collector tutorial,但我在教程中的代码中遇到了一些编译问题。
我一直在 Visual Studio 中跟进,在头文件中创建访问器方法时,我使用 Intelli 感知来生成对应的类。
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 代码添加的定义,但我不确定它应该用于什么,没有它就无法编译。 (教程中没有这个定义,但是 VS 要我添加它。)
据我所知,我已经为这两个 UFUNCTIONS 定义了方法,但是如果我没有生成的定义,我会在虚幻引擎中得到编译错误。
D:/Unreal Projects/BatteryCollector/Source/BatteryCollector/Pickup.h(25) : Error: Function return type: Missing variable type
谁能看到我做错了什么或遗漏了什么?
【问题讨论】:
-
@un 码在您的问题中输入错误消息,而不是提供带有错误的图像。
-
删除图片并添加文本版本。
-
Pickup.h-UFUNCTION(BlueprintPure, Category = "Pickup"); -
没用过Unreal-engine,但是我注意到SetActive和IsActive之间是有区别的,IsActive的bool前面有个分号?是预期的吗?
-
@foreknownas_463035818 OP 也将分号添加到其他函数中。请 OP,删除两个分号。
标签: c++ unreal-engine4