# inheritance in structs?

**URL:** <https://forums.unrealengine.com/t/inheritance-in-structs/432267>\
**Category:** Editor Scripting\
**Tags:** Struct, inheritance, inventory, unreal-engine, Blueprint, question\
**Created:** [August 23, 2018, 8:43am UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267 "2018-08-23T08:43:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4116411d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4116411d](https://forums.unrealengine.com/u/anonymous_user_4116411d)\
**Post date:** [August 23, 2018, 8:43am UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/1 "2018-08-23T08:43:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 23, 2018, 8:53am UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/2 "2018-08-23T08:53:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [August 25, 2018, 5:25pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/3 "2018-08-25T17:25:46Z")

</div>

If you want functions and inheritance, I would use Objects instead of structs.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4116411d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4116411d](https://forums.unrealengine.com/u/anonymous_user_4116411d)\
**Post date:** [August 26, 2018, 2:58am UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/4 "2018-08-26T02:58:13Z")

</div>

and what if it didn’t have functions? just data with inheritance, would you still recommend objects?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [August 27, 2018, 10:35pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/5 "2018-08-27T22:35:44Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [August 27, 2018, 11:44pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/6 "2018-08-27T23:44:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [August 27, 2018, 11:45pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/7 "2018-08-27T23:45:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 29, 2018, 9:38am UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/8 "2018-08-29T09:38:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [December 4, 2018, 11:41pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/9 "2018-12-04T23:41:20Z")

</div>

It was for the OP

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [September 22, 2020, 5:50pm UTC](https://forums.unrealengine.com/t/inheritance-in-structs/432267/10 "2020-09-22T17:50:00Z")

</div>

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
