4

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

}
Pimgd
  • 5,983
  • 1
  • 30
  • 45
Baby Coder
  • 759
  • 1
  • 7
  • 14

1 Answers1

2

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

}
Baby Coder
  • 759
  • 1
  • 7
  • 14
  • Do I have to inherit from UObject to make class visible in editor so I could make blueprint of it? – Roman May 03 '16 at 13:59