Struct with methods

Hello.

Is there any way to create the blueprint that contains data and simple methods to access it to use mostly like a structure?
Something like C++ structure with member functions …but without C++.

Thank you.

Or even created with C++ but exposed to blueprint.

The goal I’m trying to achieve is using custom Set/Get methods on the structure from inside the blueprints.

Try an interface. You tell the Interface what Functions are attributed to it, then when you create a blueprint it can Implement that interface, but you’ll have to implement the functionality yourself.

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Types/Interface/UsingInterfaces/index.html

I was hoping to use member functions in a pair with interface to implement some kind of multiple inheritance.
For example:

  1. I have character stats like health and vitality, the firsts depends on the second so changing vitality also changes current and maximum health. This logic is implemented inside MyStatStruct methods.
  2. I have IHaveStats interface with Get/Set Health/Vitality.
  3. When I need to create an object that has these properties I add a variable of MyStatsStruct type with its fields exposed to the editor and then implement the interface functionality just connecting interface calls to already-programmed structure methods.

I have probably found the way to do it creating structures in c++, but I need to check this out and I can’t do it now =( So I’ll comment on this later.

p.s. And I know that I can achieve the same mechanics with nested inheritance but then I still need to implement get/set logic more than once.

Update: It doesn’t compile because “USTRUCTs cannot contain UFUNCTIONs”.
And this is kind of strange.

USTRUCT(Blueprintable)
struct FCharacterStats
{
GENERATED_USTRUCT_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
int32 vitality;

FCharacterStats();

void SetVit(const int32 NewValue);

};

This compiles fine until I add UFUNCTION(BlueprintCallable, Category=“Stats”) for the SetVit method.

The only workaround I’m thinking about now is creation of blueprint library with set/get functions for each of the structures I have.

I’ve found this:

But there seems to be no way to call ObjectInitializer from inside the blueprint. So back to code or static blueprint libraries.