很抱歉,我收到了一个非常虚假的问题,我一直在研究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
任何人都可以看到我在做错或丢失的事情吗?
答案 0 :(得分:3)
UFUNCTION([specifier, specifier, ...], [meta(key=value, key=value, ...)])
ReturnType FunctionName([Parameter, Parameter, ...])
该声明中没有;
,很可能是问题所在。
请注意,在编辑问题的过程中,您还向其他声明中添加了;
,但是您应该将两者都删除。
PS:我将其发布为答案,希望将半垃圾评论变成有用的东西。我不知道虚幻,也许这个答案是错误的,那就让我知道。