x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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)
 {
 
 }
 
Product Version: UE 4.8
Tags:
more ▼

asked Jul 07 '15 at 06:37 PM in C++ Programming

avatar image

KikyoPorter
22 15 17 17

avatar image spazchicken Jul 07 '15 at 07:02 PM

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;

avatar image KikyoPorter Jul 07 '15 at 07:53 PM

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

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

It seems you have problem understanding UE4 framework, i see 2 problems

  1. 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.

  2. 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: https://docs.unrealengine.com/latest/INT/Gameplay/Framework/index.html

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

more ▼

answered Jul 07 '15 at 07:04 PM

avatar image

Shadowriver
35.2k 921 166 1098

avatar image KikyoPorter Jul 07 '15 at 07:20 PM

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

avatar image Shadowriver Jul 07 '15 at 07:58 PM

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

avatar image KikyoPorter Jul 07 '15 at 08:02 PM

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)

avatar image Shadowriver Jul 07 '15 at 08:15 PM

Ok then, keep in mind UE has APIs for HTTP and JSON 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

avatar image KikyoPorter Jul 07 '15 at 08:22 PM

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

(comments are locked)
10|2000 characters needed characters left

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

more ▼

answered Jul 08 '15 at 03:04 PM

avatar image

KikyoPorter
22 15 17 17

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question