简体   繁体   中英

How to create a custom c++ class to use with blueprint

I am trying to create a custom class that i can then use in my blueprints. I need this class to hold player information like name and a path to their picture. What I have made so far doesn't compile or build without errors and I don't know how to fix it since I have never worked with this

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 file

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

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

void UPlayerClass::importPic_Implementation(Fstring picPath)
{

}

what I found is that my importPic function needs

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

and depending on if you want your class to show up as a blueprint variable or to be able to be made into a blueprint class you would change the top heading to

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

the code that built and compiled:

header file

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM