Download

Basic Item System with stacking functionality - Please Critique!

This is my first real attempt at an inventory system but I think I did a pretty decent job so far. I am creating this using the top down blueprint template with the starter stuff included.

I’m just going to give screen shots and a high level overview, I believe most people here should be able to figure out how to replicate my process if they want to. If anything needs expanding let me know and I can edit the post as needed.

Static Mesh

  1. Create a basic mesh as a place holder for an item, set up collision, and enable physics
  2. Create a blueprint from this item (BaseItem)

BaseItem
Create the following variables:

  1. Name - Name
  2. Bool - Stackable
  3. Integer - Current Stack Size (1)
  4. Integer - Max Stack Size (1)

BaseStackable

  1. Created as a child blueprint of BaseItem
  2. Set Stackable to true
  3. Set Max Stack Size to 10 for testing purposes

Inventory Blueprint

  1. Create a new blueprint -> Actor and named BaseInventory

  2. Added a sphere component and set radius to 100

  3. Created the following variables:

  4. Integer - Max Inventory Size

  5. Array of Actors - BaseItem_C

  6. Bool - Has Partial Stack

  7. Integer - Item Slot Number

Created the following Macros and 1 Function:

  1. Event Graph
    82fcf81a795b82743cfa0a4b080cb825f954db44.jpeg
    Whenever the sphere around the inventory, which is now attached to the pawn in the pawn BP, collides with BaseItem or a child, proceed to see if the item can be collected.
  2. Macro - Can it stack
    Can it stack.PNG
    This is very straight forward. If the item isn’t a stack able item it skips to checking for inventory space. This is designed to skip over items like equipment.
  3. Macro - Check for partial stacks part 1
    Partial 1.jpg
    This part looks complicated but I hope I can explain it well. This part searches the existing inventory array to see if the incoming item name matches the name of any of the array elements AND if that element isn’t a full stack. If it cannot find an item matching the above condition, it sets the bool (has partial) to false so that when the loop ends it can bail out and jump to the next macro. If the condition is met however, it sets the bool to true, and sets the Item Slot Number integer to the array index, and bails out of the loop since we don’t need to look for more items with this condition.
  4. Macro - Check for partial stacks part 2
    Partial 2.PNG
    Since we did find a partial stack, lets get the reference to that item by searching our inventory again for the array index that was previously set. Once we find said item, lets get its stack size and increment it +1 and destroy the incoming item since we don’t need to see if any additional spots are open in our inventory.
  5. Macro - Check for inventory space
    182cdeaa4d9c1d598113b7c89acda6721bd24ddb.png
    This is pretty basic. If the number of items in our inventory is less than the total number of items specified in the Max Inventory Size integer, then move on to the following function. If it is greater however, bail out with a simple error message.
  6. Function - Add item to inventory
    38fb9b67581d892bfe0cd4a37541e782262a558b.png
    This simply adds the incoming item to our inventory array and destroys the mesh

Pawn Blueprint
Created a sphere component around the pawn with a scale of 3 for XYZ.
ecbecb08b334205f547182a08bbbd3263ead298d.png
This event graph spawns an invisible reference to the inventory actor which, using the sphere generated above, is used to detect when the player runs over a collectible item.

Please be gentle :slight_smile:

Thanks,
Haka

PS: please disregard the attachment file for the Add Item that includes the Last Item, Get, and Set functions. They are not needed.

I’m confused as to what kind of inventory this is. Is it a Rts style Inventory where you purchase items that increase base levels?

This is intended to be more along the lines of R.P.G. inventory like Diablo except without the whole items taking up more than 1 slot. I don’t even want to attempt that. The items that stack would be like potions or use able items and non stacking items would be like equipment.

Inventory is one of those things that I haven’t dug into so I haven’t really understood how it is handled. Just your overview, without the screenshots, goes a long way to bridge that conceptual gap. I will have to keep up with this thread for the day I begin to implement similar(vaguely) features in my Civ game. Good luck! :slight_smile:

this is awesome, any chance we could see a video sample of what it looks like when you are playing? If not, no big deal, I will just try this out when I get home tonight

Sadly my internet speed is horrible from living way outside of town (this should change soon hopefully) so I took some screen shots. Hopefully you can infer from them what is going on.

Stackable pickups.png
Here I am running around grabbing the golden squares which are my stackable object and just print some basic information to the screen.

Stackable pickups2.png
Here I am grabbing my metallic squares which do not stack.

Does this help illustrate what’s going on more?

-Haka

Hakabane, thanks so much for your examples. Sharing your prototype is a very important step for the rest of us to even know where to begin!

Looks cool! Do you have plans to consume items and reduce the stack size by 1, as well as splitting stacks?

Thanks Hakabane thats really cool! :slight_smile:

@Zooch - I have quite the wishlist of things I want to do with the inventory. I will flesh that list out later on this week and post back here what I want to add and start posting what I’m able to accomplish.

@Ulrich - I’m honestly just happy to be able to give back. In my UDK days I had people help me all the time with issues I had.

I’m trying to follow along but I’m getting a little confused. :frowning: Could you please do a video? Pretty please with sugar on top?

video is out of the question since I’m on just better than dial up connection right now. Once I get a job again and can afford to live in town I plan to make many videos to help people out. What part are you confused by?

Hi there. i got to the first event graph but I’m not sure where any of those graphs go, exactly. And it wouldn’t let me put the Inventory blueprint into the “MyCharacter” blueprint as a component (using the 3rd person template) since you said to do that to the pawn.

I’m going to see about creating a video for this and I can just drive to my friends house to upload it.

can you share it somehow pls ?

That’s my plan. I want to create a youtube channel or something to post my progress. I’d like anyone to be able to see how I got this stuff going. Eventually I think it would be cool to have a complete basic RPG starter kit for people to take and modify.

I would so thank you in my credits for going through the trouble. also i’m sure you’d become really popular and get a ton of views from other people so please do it before someone else does. you rock!
in the meantime is my question simple enough for you to answer in text?

Sorry Ovr, I’m not 100% clear on what part you’re stuck on. Can you tell me which highlighted section and what step you are stuck on?

OT, but I’m curious, how the [profanity here] do you use the Unreal Engine? I’m in a similar situation (out in the sticks using dialup, not just above dialup) and the way UE4 is set up, I’ve found it impossible to use.

Honestly I’m just very patient. Once I got it downloaded it was really just about watching videos on youtube (they buffer like mad for me) and picking up what I could. I also reference the UDK forums since most of the stuff I want has been done there and I try to translate from UE3 to BPs