Inventory system not working properly.

I’m building an inventory system in unreal engine 4.23 (I don’t think its the preview) but whenever I preview in another window by hitting launch or building the project and hit the action to bring up the inventory, it shows up and you can interact with stuff but if you pick up an item in the world it doesn’t show up in the inventory. this has happened before and I could never figure it out. Also it works in the editor but whenever I build it, it doesn’t work. I just cant wrap my head around it.

Not totally sure what kind of information you guys need, but here’s pretty whats happening, I have like 3 items in my inventory here but they aren’t showing up.

This is in the build:

Here it is in the editor: what its supposed to look like.

So I was taking a look out output logs and I noticed whenever I picked up an item it would say something like:

[2019.10.01-03.47.21:284][824]LogScript: Warning: Script Msg: Attempted to set an invalid index on array Inventory [-1/15]!

So I’m guessing it has something to do with my array set up.

If anyone wants to have a look at it here it is:
https://drive.google.com/file/d/15-4OML1NReNvPl4OtkGjhhOzdpsZ4lmE/view?usp=sharing

Google doc because it exceeded the upload limit here.

Can you show your code for ‘display inventory’?

So I believe this is what your asking for, its my toggle inventory function

Here is how I use the function Toggle Inventory:

Not sure if my reply went through.

I guess your asking how I toggle the inventory, so here it is

I have it in a function called Toggle Inventory, which pretty much just creates the widgets and displays/removes it from the viewport.

And then I call it from the player character like this:

This is the Prepare Inventory Function called after the get node.

Also I have 2 blueprints being created here, The UI_Inventory and the InventoryWindow, UI_Inventory has the character image and other information, the InventoryWindow just handles the inventory (I.E. The ItemGrid, which displays item information)

Sorry if its a little messy I’m learning.
If you need anymore information just let me know

Also I removed the set input UI only cause I think its messing with my health bar for whatever reason, and also the pause game from the is not valid branch. but that’s an issue for another day

What are you building for? Windows 32x? 64x? Mobile? Last time I had problems with the build I forgot to check the plugin only worked with Windows 64x

Ok, one thing before I spend ages looking at those BPs. Can you just CLEAR your array(s) before you start. I’ve seen this appearing in the engine on a number of occasions recently, arrays behaving strangely, and it goes away if you explicitly clear the array during initialisation.

Hi - so I looked at it and don’t see anything too strange. Although I don’t really get the prepareintentory function. Why resize? Also, why set everything to default, surely it needs to retain it’s current properties?

Could well be I’m just totally missing something there…

Do try just doing a CLEAR on that inventory array on beginplay though…

Ok will do then I’ll get back to you if it worked or not!

Where do you think I should clear the array? Whenever the inventory is open or whenever it is built, sorry for the stupid questions im new to the game development scene

I’m building for x64.
And I think that makes sense because I was running debug on the launcher and at one point it said something like windows doesnt support plugin but im not sure which plugin though

ok I just saw the last part, on clearing it from begin play, disregard my last reply.

Ok so clearing the array didnt work and I am getting a bunch of warnings on my debug menu.

So Im guessing it cant call the array because it says, its itempting to call an invalid array [-1/15]
So it is definitely an array issue, but I just cant seem to find where it is going bad.

I believe it’s trying to set everything to the index -1 is there anyway I can change that?

Here is the error log im receiving

Yeah, what’s it doing up on slot 17, you don’t have 18 things in the inventory, right?

I think there might be something shonky with the way you’re add and removing items.

Some questions:

  1. Are the errors worse after you cleared the array on beginplay?

  2. What’s the minimum you can do to cause the error? ( just adding, or do you need to add and then remove )

Or you could make a new empty project and migrate just your array code to that and put a link up here, then we could take a look…