Hey all, I am trying to create an inventory system but wondering how is the best way to go about this, I was trying to structure blueprints but I can’t find a way to polymorph them. basically I want a blueprint ‘Inventory’ that has 40 slots, so will have an array of 40 ‘Inventory Slot’ blueprints which contain 2 variables, int quantity and 1 ‘Item’. this is where I am not sure what to do, I want ‘Item’ to be a class / struct / blueprint with variables and functions as an abstract that other items will implement. such as If I have 10 sticks in my inventory it will be structures like… Inventory location will be an InventorySlot with Stick as the Item object and 10 as the qty, and Stick inherits Item.
what blueprint should I use for the Inventory and Inventory Slots, and how should I do the polymorphism relationship between Item and Stick?
I’ll see if I can find a youtube tutorial on this when I get home (unless someone beats me to it) but the base premise is that you have a base class which all other items are derived from so you can cast back and forth. Inventory would then be an array of struct f.ex. 1) int id 2) int amount 3) BP_MasterItem Item
I’ll try to make it clearer when I get home, if needed
video is unavalible, I have started working on it however my item ‘ItemStick’ is saying ‘wrong class’ when trying to create an instance of it in game, no idea what’s wrong here, why is there no simple Constructor to use? I am trying to add an instance of ItemStick class into the inventory… this should be so simple yet I can’t find anything that works.
I use a ray trace to detect objects that the player looks at, it is more accurate than a collisions box around the object. Plus when I look at it I can change the icon to a pickup hand which adds a nice touch to it like in the game Far cry 3. Also you will notice that arrays of stucts can be somewhat of an issue if you get complex with it.
I used this tutorial and expanded on it greatly, now my inventory system is legit haha…
ok guys, so I’ve got a few ideas but still need help. should I change the blueprint type from actor to something else? (i would like to do this but no idea what to do since structs can’t have methods or polymorphism) or should I spawn them invisibly and use the UI to access the variables such as sprites etc from it?
No idea why this is happening… I have changed Inventory to be an actor component. inventory slot to be a structure. Item to be an actor, and ItemStick a child of Item. however when debugging it, it is never creating the actor it seems. Item is none, but quantity is correct at 10. the pics bellow show the flow in reverse order.