Question about struct in BP.

I’m trying to create an inventory system and in order to load every item from a DataTable my data needs to be in a struct. The thing is i don’t want to add every possible variable in a single struct but rather to split the struct by its type (struct Item), (struct ItemEquippment : Item), (struct ItemEquippmentWeapon : ItemEquippment).

This is possible using C++ but what about BP? how can i extend a struct using BP?

Puuh, someone correct me if I’m wrong, but that’s not possible in Blueprints. You can’t extend a Struct from another Struct.

If I understand the request right, yes you can. :slight_smile:
You just add a variable to your Struct and make that variable type the other struct. Like, instead of “bool” or “float”, select [StructName].

Yeah, but that’s not directly what’s asked for.

The difference is:

  • His request means that you extend an existing Struct with new variable. Something like a Child Struct, similar to Parent and Child behavior of normal Blueprints.

  • Your idea is to create the Parent Struct and then, inside of the “Child Struct”, create a variable of that Parent Struct.

While this might be a “solution”, that’s not what he asked for AND I would not recommend to do that. Structs are pretty broken in Blueprint Only.
They tend to break when you edit a Struct, which is already in use (like adding a new Variable). Or they disconnect on start-up of your project (which happened
to me lately after converting to 4.12).

So the best idea would be, to create the structs in C++. Then you can have your Parent/Child Struct and also avoid these nasty BP bugs.

You could use an Actor Class instead of struct for this, so they would be data only…

In C++, Struct are almost the same as a Class, and the Actor class is the most primitive class, afaIk, that can be replicated, so it would not be expensive for you.

Actors class is WAY too big for such a purpose. An Object would be the most primitive class. And event that shouldn’t be used to replace a Struct.

Totally agreed, but Object class, afaIk (might be wrong, need to take some time inside the code to see), cannot be replicated… could be a bottleneck for a MP game.

Actor class should not be treated as a conventional variable in terms of having multiples for single/specific uses. But, for his purposes, I believe it would be more expensive in terms of processing to have it breaking two(or even more) structs (as mentioned as a solution before) every time you need to access the variables you wish, not to mention the algorithm complexity could reach another level inside the functions.

But that came from my personal reading of the problem, there’s the possibility I could be misunderstanding/not considering something :slight_smile:

Well yeah, they can’t replicate themselves. But you could replicate the object as a subobject. (Just as a sidenote)

not sure if it applies to your case, but I did something similar.
Pulling data from a table, each line of table converted to a Struct, create an array of these structs, update individual structs as required,
couple of issues initially with structs updating for 1 tick but not overwriting values and reverting to original value,
not sure if using the “insert” fixed it or just closing and re-openning project. First tried Struct of structs but it would not work as expected, so ended with array of structs, which seems to work, this was based on NPC stats so didn’t go as far as saving data or updating datatables.