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 are your errors?
First thing i see right off the pat is that your
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Switch Variables” needs a ) at the end
like
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = config)
string mystring;
It seems you have problem understanding UE4 framework, i see 2 problems
- And it’s cause of your errors, you use C++ standard library which reflection system does not support it, there for UHT (not compiler) give you errors on UPROPERTY. UE4 has it own implementation of standard library and you should use it with UE4, so instead of using std::string use FString. You can use C++ standard library, but then you need to keep it outside of reflection system by removing UPROPERTY before variables, also you will have problems to use those with the rest of engine code. In general it means you wont be able to use most engine features with them. I don’t want to write a lot about basic, so here general tip, don’t use anything outside UE4 APIs if UE4 has something covered… and it has a lot things covered. If you just starting with C++, maybe try using UE4 basic tutorials instead of general C++ basic tutorials, as they use different APIs, but syntax is still the same as you still use same C++ in both just with different standard APIs.
- I don’t understand why you want to create own Player class if UE4 already have them and you can extend them. Each player has UPlayerController which can contain player data, also UPlayerState for replication. There also UPlayer but i’m not sure if you can extend that class. here you got docs about UE4 framework: Gameplay Framework in Unreal engine | Unreal Engine 5.1 Documentation
Also one small thing, UE4 use diffrent naming style, insted of starting function and varable names with lower case, start with upper case and each next word also with upper case. It’s not a big deal, code will build without it, but with UE4 APIs which has different style your code might look messy overtime
Thank you very much for explaining that. I am new to Unreal c++ (I’m ok with regular c++ coding) The name of the class is kind of deceptive. I really just need this class to be a container to hold player information. I’m using this class as a bridge to unreal. I need to import pictures and information from a different server on the fly and I can’t do that through blueprint. I need the class to take information from a proxy and add it to a csv that I can then add to an unreal data table. This class will be in the background and not actually seen or controlled. I wasn’t quite sure what the set up for that class would be.
I actually don’t even know if being a child of UObject is what I want. I was trying to see if extending my class from an already existing class that shows up in blueprint would help my class show up in blue print
Error 3 error MSB3073: The command ““C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat” Prototype2Editor Win64 Development “C:\Users\PorterN3\Documents\Unreal Protype\Prototype3\Prototype2\Prototype2.uproject” -rocket” exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 Prototype2
Error 1 error code: OtherCompilationError (5) C:\Users\PorterN3\Documents\Unreal Protype\Prototype3\Prototype2\Intermediate\ProjectFiles\Error Prototype2
By server do you mean? Some known online service, since UE4 support some of those too. Generly for implement other online services you should use OnlineSubsystem interface, but if you newbie then it might be too much for you for begining
no it’s not an online service. It’s an in-house system. It will be sending unreal engine data and unreal just has to update/populate data tables. It also has to be able to import images from paths that the server will be sending. (still working on trying to figure that out)
Ok then, keep in mind UE has APIs for HTTP and and XML i think and as well as normal socket for any protocol, so if you use those you will have outputs in UE4 types ;] If not remove convert C++ standard types to UE4 types
ok thank you
I changed some of my code earlier
this should work, right?
#pragma once
#include "Object.h"
#include "PlayerClass.generated.h"
/**
*
*/
UCLASS()
class PROTOTYPE2_API UPlayerClass : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
FString playerName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
FString playerTeam;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
FString picPath;
//UPlayerClass(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintNativeEvent, Categtory = "Switch Functions")
void ImportPic(FString picPath);
};
because I still keep getting intellisense errors and this MSB3073 error
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)
{
}