如何创建自定义c ++类以与蓝图一起使用

时间:2015-07-07 18:42:14

标签: c++ compiler-errors unreal-engine4 build-error unreal-blueprint

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

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)
{

}

1 个答案:

答案 0 :(得分: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)
{

}