i am currently trying to make an inventory system in unreal and wanted to use a struct for the items, my idea was to have a struct that haves a name and then have children for Gun, consumable, resource, each of them with their own functions and variables, but i realized i can’t make a children from a struct.
is there any way to do this or get something similar using blueprints?
You can have an array of structs which can have an arrays of other structs inside. There is no struct graph where you can script things, though. Struct is just a collection of data that is easier to access.
Normally, you’d have an Inventory Actor that holds arrays of structs, and this actor would handle the inventory. Adding, Removing, Splitting, Finding, Replacing functions and so on.
If you want functions and inheritance, I would use Objects instead of structs.
and what if it didn’t have functions? just data with inheritance, would you still recommend objects?
Object still can work as data holders, in C++ objects are no different from structs, in UE4 ofcorse they have UObject management, but it not such a big deal and it actually gives you benifits as with that you are 100 sure you referencing item not copying it.
And yes in C++ you could use structs the way you want, but blueprints don’t support struct inherence from C++ as well as functions (but this can be worked around with static functions in class)
IF you want it to work the way a struct does in , I think there is a plugin for unreal that you can add to your project, and you could work with strings instead.
The thing about Structures in Unreal (if that’s what you are referring to) is they are Assets with a statically defined set of keys. If you want something more soft-typed than that which can change its keys at runtime then you’ll have to use something else.
Not sure what you’re referring to @Mightyenigma. Is this a comment for me or for the OP?
@anonymous_user_979758af: I’ll just add that wrapping structs in actor components works really well since components can inherit. They’re a bit more lightweight when compared to an actor.
It was for the OP
the problem is that structs can have predefined values, which is quiet useless unless you have only one struct instance
(which makes no sens at all)
so the question remains, from one struct definition, it would be nice to be able to create prefilled instances