x

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"

How do I implement different items to work in the same inventory system?

I cannot wrap my head around something so seemingly trivial. I have an inventory system that already has a physical and UMG-oriented add/drop/move system (think any standard slot-based RPG inventory). I have a custom class called ItemBase that is used throughout this system. Everything works great - except for when I get to implementing different items. Basically, ItemBase holds a struct ItemInfo for standard variables that all items will have such as Value, IsStackable, Name, etc. I would assume to make a weapon class I would make a child of ItemBase, call it WeaponBase, then add a WeaponInfo struct to this class. My problem arises when I want to add functionality to the child class. My WeaponInfo struct would hold weapon-only info such as Damage, Attack Speed, etc. I'd like to display this info on a tooltip UMG, have such info affect the character's stats, and so on. However, all of my functionality only works with ItemBase. It cannot work with WeaponInfo since WeaponInfo doesn't exist in ItemBase. What am I doing wrong? Should ItemBase hold substructs for all different items (WeaponInfo, ArmorInfo, ConsumableInfo)? This seems like it would be a waste of performance no?

Product Version: UE 4.18
Tags:
more ▼

asked Jan 17 '18 at 04:55 AM in Blueprint Scripting

avatar image

Pharros
23 1 2 7

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Hey there, ideally WeaponInfo should derive from ItemInfo, that way you still have what's in ItemInfo plus the weapon stuff. The problem is that in blueprints you can't really do struct hierarchies.

more ▼

answered Jan 17 '18 at 02:47 PM

avatar image

xlar8or
6k 160 128 304

avatar image Pharros Jan 17 '18 at 02:59 PM

Yeah I was thinking in BP that I might need to have ItemInfo consist of substructs. So for example, WeaponInfo would apply for WeaponBase, but not ArmorBase. What worries me about this method is I think it would mean all items would contain useless data. So Armor would have default values for WeaponInfo (despite not ever applying it). Would this cause bloating once compounded?

avatar image xlar8or Jan 18 '18 at 11:07 AM

The problem is that in Blueprints aparently you can't create sub-structs, so you can either create them in c++ or you need another approach. In my case every item i pick is the one i use, so i have the item as an actor and that has the information, then i have WeaponItem, ArmorItem, etc.

avatar image Pharros Jan 18 '18 at 07:57 PM

Wouldn't that mean you would need to have identical functions for all items then? for example, if all items can be picked up, it would be redundant to make a pickup function for all possible clases rather than a singular parent class that could then allow children to share the functionality, no?

avatar image xlar8or Jan 20 '18 at 11:03 AM

When i picked up items of the same type, and they could be stacked, i would merge them into the existing one (by addind the quantity) in the inventory and deleted the picked one.

(comments are locked)
10|2000 characters needed characters left

Hi ! If you want to access a function / variable of a child from its parent, you need to use casting.

You can add for example an Enum in your ItemBase which will determine which kind of item it is ( weapon, consummable, etc .. ), so you can easily cast to the right class in your logic.alt text

Edit : You could even hold the subclass reference itself in your ItemBP info structure.

vd.png (65.0 kB)
more ▼

answered Jan 20 '18 at 11:18 AM

avatar image

leetnessdnb
34 3 5

(comments are locked)
10|2000 characters needed characters left
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