I have a structure made with blueprint, but I’m gradually migrating my code to c++. And I don’t know how to declare a structure to enter my c++ function
What’s in your struct?
this is a structure for storing items in an inventory.
int ID (standard value -1)
text Name
int Quantity
float Weight
bool Public
Textute2D Icon
USTRUCT(BlueprintType)
struct FMyStruct
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
int32 ID;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
FText Name;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
int32 Quantity;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
float Weight;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
bool Public;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStruct")
UTexture2D* Icon;
FMyStruct()
{
ID = -1;
Quantity = 0;
Weight = 0.f;
Public = false;
Icon = nullptr;
}
};
By text, I’m assuming you mean FText?
Name FMyStruct to whatever you want, but keep the leading F.
Modify the UProperties based on how you want to access the struct.
Category can be anything you want.
Hi there @AzureStrannik,
This topic has been moved from International to Programming & Scripting: C++.
When posting, please review the categories to ensure your topic is posted in the most relevant space.
Thanks and happy developing!
Have a easy way to do this:
- open your blueprint in editor
- menu → asset → preview equivalent c++ header
the question was rather about whether it is possible to use the structure declared in blueprint in c++ code. but apparently the answer is no. apparently, i will have to rewrite all the functions that involve the structure before using it in c++.
@xenofsnstudios has the closest to an answer.
@dagon1999 “preview equivalent c++ header” I didn’t find it, apparently it was added to ue5.
And I still don’t understand where I can declare the creation of a structure because if I declare a structure in an actor or a pure c++ class, then I get an error on the line
GENERATED_BODY()
and specifically, I don’t see the USTRUCT class in the choice of creating c++ classes
you can create a empty file name MyStruct.h
and add
#include "MyStruct.generated.h"
to MyStruct.h before xenofsnstudios code
FMyStruct()
{
ID = -1;
Quantity = 0;
Weight = 0.f;
Public = false;
Icon = nullptr;
}
Best practice is to use an initializer list. Basically that runs first, the constructor runs second.
FMyStruct()
: ID (-1)
, Quantity (0)
, Weight (0.f)
, Public (false)
, Icon (nullptr)
{
}
which version are you using? I cannot find it