Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

inheritance in structs?

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?

Product Version: UE 4.20
more ▼

asked Aug 23 '18 at 08:43 AM in Blueprint Scripting

avatar image

73 3 8 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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

more ▼

answered Aug 25 '18 at 05:25 PM

avatar image

3.8k 18 20 20

avatar image Nico_Pucho_27 Aug 26 '18 at 02:58 AM

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

avatar image Shadowriver Aug 27 '18 at 10:35 PM

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)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Aug 23 '18 at 08:53 AM

avatar image

13.8k 74 25 58

avatar image mightyenigma Aug 27 '18 at 11:44 PM

IF you want it to work the way a struct does in jSON, I think there is a JSON plugin for unreal that you can add to your project, and you could work with jSON strings instead.

avatar image mightyenigma Aug 27 '18 at 11:45 PM

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.

avatar image Everynone Aug 29 '18 at 09:38 AM

Not sure what you're referring to @Mightyenigma. Is this a comment for me or for the OP?

@Nico_Pucho_27: 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.

avatar image mightyenigma Dec 04 '18 at 11:41 PM

It was for the OP

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question