How can I have a basic inventory system and spawn an item when I call a function?

Hey, I’m making a basic inventory system and want to be able to spawn an item when I call function “DropItem”, issue I’m having is, when I try to connect my Inventory var, it is saying that it is not compatible with an Actor, only an object, anyone of you smart people got any solutions for me ? thank you ! :slight_smile:

After “Get” put “Get Class”.

Pierdek

Sorry about long delay, When I do that I get Class"Object" Is not compatible with Class"Actor" any way to fix this?

Well you can’t spawn non Actor class, you can try cast your inventory type to actor or change variable type in inventory items array from object type to some actor type.

Make an Array of Type Class Actor. Set your ItemsClasses manually in that Array (Your Item Blueprints).
Make your inventory an int Array. values inside array are indices of ItemClasses array.
If you want to spawn Item from your Slot 0 of your Inventory array, get Int Values of that slot and plug it into Indexslot of ItemClasses Getnode. Than spawn this class.

As eXi mentions, you’ll want to use a Class Actor array rather than an Actor array. When you select Variable Type, it will look like this:

13196-classactor.png

Hope that helps!

Ahhhh, Perfect, eXi, thank you, one last question, is there a way to add variables to class’Actor’ via blueprint and not manually? Atm, I spawn with items in my inv by default and can not pick any items up once dropped, thank you ! :smiley:

I use a Function(UsableActor) and have a line trace inside, so that when I call function, it traces for object i’m looking at, and returns it, I can’t seem to get called object to store in ItemClasses Class’Actor’ array

Tom Looman has done an amazing job with a basic inventory system tutorial that implements “usable actors” to manage inventory. I strongly suggest you go through it.

Hope this helps you as much as it helped me.

I have been through Tom Looman’s Inventory system, I built first half of Tut in BP and then found second half was based on first half being c++, this confused me and I spent around a week to no avail so started on my own, seemed to have gotten further on my own but now I’ve hit a wall, if you have any suggestions on how to do second half of tut based on first being BP please let me know :slight_smile:

If you notice beginning of this thread was actually Tom Looman’s BP setup, first issue of this thread was caused by being confused of Tom Looman’s guide, just wish he would make a Part 2 based on his Part 1 BP and not C++

Sorry if this post confuses you;
Tom Looman’s guide is setup in two parts;

Part 1, Shown in C++ and BP
Part 2, Shown in BP but based on Part 1 C++ and not BP

Implementing second part (Inventory Section) to First BP Line trace gave me initial error of this thread.

And although I do have VERY basic C++ knowledge so I could probably do first part in C++, I am making projects solely on BP’s to understand them better, as Epic have stated it’s possible to make games using BP only, I want to try ! :slight_smile:

He updated tutorial to do whole thing in blueprint. That’s how I figured out system. It must have been updated since you were there.

Just been on to it and on part 2 of Inventory system, it still reads

"Introduction

In this part I will show you how to build a basic inventory system to pickup, select and drop items from a player’s inventory. Please note that this tutorial was written based on C++ Part 1 tutorial"

What parts did you do differently than what guide says? because following it exact doesn’t work for me.

I used a “Get Class” node to get the “Pickup Class” by dragging a wire from GET and typing Get Class with context sensitive on. See two attached pics. Let me know if this solves your issues.

It may be possible that you missed something int tutorial that created custom “PickupClass” actor type…

Yeah, that has worked but now when I hit ‘E’ It calls the “usable actor” and does nothing with it, item stays on ground and nothing gets added to my inventory, do I need to add item? if so how do I get usable actor to join add node? I have work so will reply as soon as I can, thanks :slight_smile:

ItemClasses isnt array where you save your variables. It is just a list of all Items so that you can spawn them.
If you want to save items, you need to make a Struct inside your Item with alle properties and an Array of same Struct inside your player.
Than you need your int Array to have a value like -1 for empty places.
If you find an item with your UsableActor function, you check for an empty place in your inventory (one that hasnt got a -1 or is same item and can be stacked) and add alle information of item to matching slot on character.
My inventory for example is created with following arrays:

Int Array (Inventory for Spawning)
Class Array (List of all Items so you can spawn them)
Properties Array (Array of Struct that is from Item Struct and defines all values of item)
StacksCount Array (Array to track amount of stacks an itemslot has)

Despite Class Array, all other arrays stand for same item sharing same index.
So on index 0 there could be a stone. So values are in Properties array at 0. I have 2 Stones at this slot in my inventory. so StackCount has a 2 at index 0. My Matching Class ist at 10 slot of my Class array. So my IntArray got a 10 at index 0. And so on.
Its a bit complecated at first, but after a while you understand why you need this and how this works.
I recommend to resize arrays to your maxium Inventory size and only set array elements to specific indices instead of just using add function.

Turns out i’d messed up more trying to solve first problem I had and by time I had fixed it, i’d done more damage than good, I was considering starting from scratch but decided i’d learn from my mistakes and traverse through bps to correct what I had done, it’s now 6am and I’ve had no sleep anyway I have finally figured it out, I will get hang of this one day!