Announcement

Collapse
No announcement yet.

Items not being added to inventory (Solved)

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

    Items not being added to inventory (Solved)

    Hi, for some reason items aren't being added to the inventory, even though the items always follow their correct path and hit their correct return node as successful. I've tried using Get Reference and Get Copy but it seems to make no difference, I've also made the Inventory array inputs on the functions pass by as reference and that didn't make a difference either. I have no idea why this is happening, because I have it on a different project which works fine, but is slightly different (I'm trying to remake it in this one), though nothing has changed in these areas and they are receiving their correct inputs, so I don't see what's going wrong.

    Click image for larger version  Name:	InventoryHelp2.png Views:	25 Size:	187.5 KB ID:	1844281
    Last edited by Mikester4411; 12-21-2020, 08:32 PM.

    #2
    Bump
    It's been a day and I still haven't been able to see where I've gone wrong, can anyone help please?

    Comment


      #3
      Bump......

      Comment


        #4
        Bump!

        Come on, it's been 5 days I've been stuck on this now, and I've not gotten anywhere, it's forced my project to a standstill and I have no idea what's going wrong, I've lost count of how many different tests I've made printing the strings and using break points, returning copies and references, but to no avail, everything is executing as it should, returning the correct variables, locations, items, etc..., just nothing is being added to the array, where am I going wrong!? Is it because this project is 4.26 rather than 4.25 where the original project is? It shouldn't make a difference though, because this is a new project, not one being updated to 4.26

        Comment


          #5
          Buuuuuuump

          Comment


            #6
            I dont see any thing related, put the whole code here.

            Also try debug it yourself trying add breakpoints and check all things step by step.

            Comment


              #7
              Originally posted by AmiRSlaYeR View Post
              I dont see any thing related, put the whole code here.

              Also try debug it yourself trying add breakpoints and check all things step by step.
              I've tried debugging it myself for 6 days now, I've added break points and print strings at every step, and everything is executing correctly when it should be, and giving/receiving the correct variables that it should when needed, so there's nothing wrong with the rest of the code, the problem is that nothing is being added to the array, which isn't making any sense because it knows what inventory and sub-inventory it's adding to, and what item and amount should be added

              I even created a quick debug code to force giving myself an item using this code here, but that didn't work either (I'll only show this code because I have about 10 functions and some are quite large, but all work as they should, it's literally just the adding to the array that isn't working)

              Click image for larger version  Name:	InventoryHelp3.png Views:	0 Size:	141.2 KB ID:	1845802

              This is the Find Sub-Inventory function used, which again, works exactly as it should:
              Click image for larger version  Name:	Find Sub Inventory Function.png Views:	0 Size:	145.9 KB ID:	1845803

              (The 'Find Item Info from Slot' macro is literally just a Get Data Table Row that uses the name of the item to find the row, and returns the row with all of the items info)

              The only thing I can actually think of is that I'm trying to edit an array that is part of an array of structs, and for some reason it's not letting me edit that (even though in the old project it did), but I have no idea how I would get around that, or why it's not letting me in the first place...

              It's set up so the Inventory variable is an array of Sub-Inventory structs, which each sub-inventory contains its name, max slots, etc..., and an array of slots, and it's the array of slots that I'm trying to add to/edit, nothing else in the code is relevant because it prints the correct information when it tries to add the item (the item itself, amount, location, and the inventory it's adding to), but doesn't add a slot, and prints 0 when I print the new item's index.


              Here's the values the Add is receiving when using a break point on the Add node:
              Click image for larger version

Name:	InventoryHelp4.png
Views:	96
Size:	114.9 KB
ID:	1845811
              Last edited by Mikester4411; 12-22-2020, 03:48 PM.

              Comment


                #8
                why you add +1 to the array last index? it's an array and last index +1 is not valid i guess.
                what's the logic in add a value to an array length instead of taking(substract) 1 from it ?
                Last edited by AmiRSlaYeR; 12-22-2020, 03:59 PM.

                Comment


                  #9
                  Why isn't row not found connected to anything, also what are your found and sub inventory index initial values, you should reset them before going to the loop.
                  Also, you have nothing going from success and there is a missing exe line to add unique.

                  Comment


                    #10
                    Originally posted by AmiRSlaYeR View Post
                    why you add +1 to the array last index? it's an array and last index +1 is not valid i guess.
                    what's the logic in add a value to an array length instead of taking(substract) 1 from it ?
                    That's the index for the new slot being created, so I get the index of the last current slot, then +1 and add that to the Inventory Coordinate struct (Sub-Inventory Index, and Item/Slot Index (both Integers)), it's basically calculating the new array element's index before it's created.
                    Originally posted by Dejan33 View Post
                    Why isn't row not found connected to anything, also what are your found and sub inventory index initial values, you should reset them before going to the loop.
                    Also, you have nothing going from success and there is a missing exe line to add unique.
                    I forgot to add a return node, but it is returning as found because everything afterwards is executing.

                    They're set to false and 0 respectively, and they are local variables so they reset every time the function is called.

                    Yeah I quickly made that code to force add a Medkit to my inventory, in the actual functions which sorts the items and adds them to specific slots or adds new slots or finding slots all use the success and return nodes everywhere, I just forgot on that one, but again it's working as it should, and the FindSub-Inventory function is definitely returning successful as seen in the last image because it's returning 2 as the sub-inventory index, which is the Consumables sub-inventory, and the AddUnique isn't being used, that was there from when I was trying to see if that would make it work, but it didn't.

                    Comment


                      #11
                      You get an array item from Local Inventory array. You then get another item from the sub-inventory array. You update the sub-inventory array, but that array/sub-item doesn't seem like it's put back in to the top-level Local Inventory.
                      In Unreal, array items are copied, and structs are value objects, not reference objects. The sub-item that you modify is a copy, not the one that lives inside the Local Inventory.

                      Comment


                        #12
                        When you use get (in all cases where you are adding something(system or subsystem) or just setting an array element), make sure its a reference and not a copy.
                        When you are adding try it with make, not some local variable struct.
                        Last edited by Dejan33; 12-22-2020, 07:39 PM.

                        Comment


                          #13
                          Originally posted by jwatte View Post
                          You get an array item from Local Inventory array. You then get another item from the sub-inventory array. You update the sub-inventory array, but that array/sub-item doesn't seem like it's put back in to the top-level Local Inventory.
                          In Unreal, array items are copied, and structs are value objects, not reference objects. The sub-item that you modify is a copy, not the one that lives inside the Local Inventory.
                          Originally posted by Dejan33 View Post
                          When you use get (in all cases where you are adding something(system or subsystem) or just setting an array element), make sure its a reference and not a copy.
                          When you are adding try it with make, not some local variable struct.
                          I understand all of that, but I AM using references, every instance of the 'Get' node used in the necessary functions are Get (Ref), not Get (Copy), as you can see with the diamond pin on each 'Get' node, and in the 'Find Sub-Inventory' function the return node output returns a reference too. Also the Inventory input for each function of mine has 'Pass-by-Reference' set to true in the function's details panel. I need to use references because I have external inventories I can trade with, such as shops, chests, other players, etc... so I can't just plug in the player's Inventory variable straight into each node requiring an Inventory, I need to pass references between functions.

                          What I don't understand is why it's not working here, because these parts of the functions are set up exactly the same in my previous inventory project, as in adding to the array inside of another array of structs, setting the array element, etc... and they work flawlessly, yet they receive the exact same information as they are here, using references, and executing at their correct times, following the correct execution paths, etc...

                          Comment


                            #14
                            What I don't understand is why it's not working here, because these parts of the functions are set up exactly the same
                            Did you set a breakpoint (select node, press F9, then run) and single-step through each node, looking at the contents of the objects of interest?
                            If so, where which exact node does not behave the way you expect it to?

                            Comment


                              #15
                              Originally posted by jwatte View Post

                              Did you set a breakpoint (select node, press F9, then run) and single-step through each node, looking at the contents of the objects of interest?
                              If so, where which exact node does not behave the way you expect it to?
                              Sorry, I took a break from the project for a bit, I came back with fresh eyes and set a breakpoint at every single step of the code, and went through it a few times and I still see absolutely no issue anywhere

                              I was using breakpoints before, but this time I literally did it for every node and watched what values each one received and returned, and literally everything was working as it should, but still nothing gets added to the inventory

                              It's behaving as if I'm editing a copy of the inventory, but every 'Get' node is returning a reference, and the input variables on all of the functions have 'Pass By Reference' checked on the Inventory input, so I have no clue what's wrong with it, but yeah, I've checked a breakpoint at every single point in the code that's running, and used print strings too, and it shows nothing out of place

                              Comment

                              Working...
                              X