Announcement

Collapse
No announcement yet.

Basic Item System with stacking functionality - Please Critique!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    1. Integer - Max Inventory Size
    2. Array of Actors - BaseItem_C
    3. Bool - Has Partial Stack
    4. Integer - Item Slot Number

    Created the following Macros and 1 Function:
    1. Event Graph
      Click image for larger version

Name:	Inventory - Event Graph.jpg
Views:	1
Size:	52.7 KB
ID:	1134380
      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
      Click image for larger version

Name:	Can it stack.PNG
Views:	1
Size:	34.7 KB
ID:	1134381
      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
      Click image for larger version

Name:	Partial 1.jpg
Views:	1
Size:	42.6 KB
ID:	1134382
      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
      Click image for larger version

Name:	Partial 2.PNG
Views:	1
Size:	144.1 KB
ID:	1134383
      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
      Click image for larger version

Name:	Check for space.PNG
Views:	1
Size:	82.6 KB
ID:	1134384
      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
      Click image for larger version

Name:	Add Item.PNG
Views:	1
Size:	57.2 KB
ID:	1134386
      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.
    Click image for larger version

Name:	Spawn Inventory.PNG
Views:	1
Size:	150.4 KB
ID:	1134379
    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 ^_^

    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.
    Attached Files
    Last edited by Hakabane; 05-05-2014, 02:17 AM.
    Movable Widgets

    #2
    Originally posted by Hakabane View Post
    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:
    1. Integer - Max Inventory Size
    2. Array of Actors - BaseItem_C
    3. Bool - Has Partial Stack
    4. Integer - Item Slot Number

    Created the following Macros and 1 Function:
    1. Event Graph
      [ATTACH=CONFIG]1511[/ATTACH]
      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
      [ATTACH=CONFIG]1512[/ATTACH]
      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
      [ATTACH=CONFIG]1513[/ATTACH]
      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
      [ATTACH=CONFIG]1514[/ATTACH]
      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
      [ATTACH=CONFIG]1515[/ATTACH]
      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
      [ATTACH=CONFIG]1518[/ATTACH]
      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.
    [ATTACH=CONFIG]1510[/ATTACH]
    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 ^_^

    Thanks,
    Haka
    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?

    Comment


      #3
      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.
      Movable Widgets

      Comment


        #4
        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!
        Map Generator 1.0
        Map Generator 2.0
        Map Generator 3.0

        Comment


          #5
          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

          Comment


            #6
            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.

            Click image for larger version

Name:	Stackable pickups.png
Views:	1
Size:	649.0 KB
ID:	1050359
            Here I am running around grabbing the golden squares which are my stackable object and just print some basic information to the screen.

            Click image for larger version

Name:	Stackable pickups2.png
Views:	1
Size:	658.4 KB
ID:	1050360
            Here I am grabbing my metallic squares which do not stack.

            Does this help illustrate what's going on more?

            -Haka
            Movable Widgets

            Comment


              #7
              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!

              Comment


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

                Comment


                  #9
                  Thanks Hakabane thats really cool!
                  reference
                  http://dirty-windows.de

                  my blog
                  http://ulrichthuemmler.blogspot.com/

                  Comment


                    #10
                    @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.
                    Movable Widgets

                    Comment


                      #11
                      I'm trying to follow along but I'm getting a little confused. Could you please do a video? Pretty please with sugar on top?

                      Comment


                        #12
                        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?
                        Movable Widgets

                        Comment


                          #13
                          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.

                          Comment


                            #14
                            I'm going to see about creating a video for this and I can just drive to my friends house to upload it.
                            Movable Widgets

                            Comment


                              #15
                              Originally posted by Hakabane View Post
                              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 ?

                              Comment

                              Working...
                              X