gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 02:21:33 27 4
gpt4 key购买 nike

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

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

}

最佳答案

我发现我的 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)
{

}

关于c++ - 如何创建自定义 C++ 类以与蓝图一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31276794/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com