4

我正在尝试创建一个自定义类,然后我可以在我的蓝图中使用它。我需要这个类来保存玩家信息,比如名字和他们图片的路径。到目前为止我所做的没有编译或构建没有错误,我不知道如何修复它,因为我从未使用过这个

header file #pragma once

#include "Object.h"
#include <iostream>
#include "PlayerClass.generated.h"

/**
 * 
 */
UCLASS()
class PROTOTYPE2_API UPlayerClass : public UObject
{
 GENERATED_BODY()
public:
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables");
 string playerName;
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
 string playerTeam;
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
 string picPath;
 UPlayerClass(const FObjectInitializer& ObjectInitializer);
 UFUNCTION()
 void importPic(string picPath);


};

.cpp 文件

#include "Prototype2.h"
#include "PlayerClass.h"

UPlayerClass::UPlayerClass(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
   playerName = "";
   playerTeam = "";
   picPath = "";
}

void UPlayerClass::importPic_Implementation(Fstring picPath)
{

}
4

1 回答 1

2

我发现我的 importPic 函数需要

UFUNCTION(BlueprintCallable, Category = "Import")
 virtual void ImportPic(const FString& Path);

并且取决于您是否希望您的类显示为蓝图变量或能够成为蓝图类,您可以将顶部标题更改为

UCLASS(BlueprintType) // for blueprint to show up as variable
UCLASS(Bleuprintable) // for blueprint to be able to be made as a blueprint class

构建和编译的代码:

头文件

#pragma once

#include "Object.h"

#include "PlayerClass.generated.h"

UCLASS(BlueprintType)
class PROTOTYPE2_API UPlayerClass : public UObject
{
   GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")
FString playerName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")
FString playerTeam;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Variables")
FString picPath;
UPlayerClass(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "Import")
virtual void ImportPic(const FString& Path);


};

.cpp -

#include "Prototype2.h"
#include "PlayerClass.h"

UPlayerClass::UPlayerClass(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
   playerName = "";
   playerTeam = "";
   picPath = "";
}

void UPlayerClass::ImportPic(const FString& Path)
{

}
于 2015-07-08T15:01:33.497 回答