Download

Loot containers

Hey, I have an inventory system and want it so if you open a loot container, it shows pictures of items that can be picked up and if you click on it then they got into your inventory. I’ve created a UMG to show the idea I want (see pic attached). Tom Looman has made a video of what I’m going for also. Thanks in advance

Just create an array that is associated with the items in the loot container, and transfer the items in the array over to the UMG slots (Loop through the array, and assign the corresponding images).

Hi thanks for the reply, although I’m not too good with UE4 just yet I understand that I already have created an array that carries my items, but the rest I don’t really understand. See the pic for what I have so far, also the freeze and unfreeze player custom events was so I could select the items with the mouse cursor but that doesn’t work, I’m not sure if that’s because this isn’t in my first person character blueprint though. If you could visually show me what you mean then that would help a lot. Thanks5e175e87e2f356da0b41b12b5330b4149fa0c1c6.png

Well, what does your ‘AddToInventory’ event do? Can you post a screenshot? Also, where are you spawning your widget?

See pic for the Add to inventory function, and I’m creating the widget in the blueprints for the filing cabinet, should this be done in the first person character? Thanksc8c051e50c0ce82bcaf21228dbde8dfbc0925b91.png

Well, there are a couple of ways to do this. Basically wherever you create the widget, you need to store it in a variable so that you can populate it’s slots whenever you want. You have two options: Create another items array in your widget, then you can just assign it to have the same value as your cabinet array. OR, you can just loop through your cabinet items, and assign the slots. Either one works, and I’m not really sure which is more appropriate for your situation, so I will have you use the latter method.

So yes, when you create your widget, save it’s return value into a variable. Now on the ‘OnClicked’ for your cabinet, you’ll need to save the images into the correct widget slots. I don’t know how you are handling your slots, so could you post an image of your expanded widget hierarchy?

What do you mean by loop through your cabinet items? Shall I create a new array called cabinet items? The slots are just buttons inside of a border for now which I have ticked so they are a variable also. Thanks

Don’t create a new array, by loop through them, I mean use the for each loop for your inventory array. Correct me if I’m wrong, but your cabinet items are being represented by that ‘Inventory’ array? But do post your widget hierarchy so that I can tell you what to do to assign things to the slots.

b0d9bded82d371a89954e9b82969448a7e97983a.png
Is any of this the widget hierachy thing you want? If not then sorry I just don’t understand

That is what I want. Since you are using buttons, we will need to be setting the button style to use the correct image. Before I tell you exactly what you need to do, I have a few questions. Is the inventory variable in your character meant to represent the items in the cabinet? What if your cabinet has more than 5 items?

The inventory items array represents items that can go into the players inventory when picked up (see pic attached for example) such as the filing cabinet key that is used to open the cabinet. I want to do it can hold 5 max, maybe even 3 max like in the BioShock games. Thanks for your help.

Ok, does your cabinet already have an array to represent items that it is currently holding? If not, make one.

No it doesn’t, so I’ve just made an array called CabinetItems in the widget blueprint, and the variable type is of that widget. Hope that’s okay

Oh, you should actually make the variable in the cabinet itself.

Alright done

You should be able to do something along the lines of this:

5746d901a68f2f904f3192f5379b2fb3651d3c11.png

This will set the button style to show the item image. You may need to check the ‘Is Variable’ checkbox for your canvas panel.

Is this made in the widget blueprint? Because I can’t get the cabinet items array because I made that in the blueprint for the filing cabinet

Also what is the ‘cabinet widget’ variable at the start? Thanks

You should make that code in your cabinet blueprint. The cabinet widget variable is that cabinet’s widget that you created, you should store it in a variable like I mentioned previously.

Okay I’ve done most of this, however I can’t get a couple of the variables, the ‘break teststruct’ and then the ‘set widget style’ at the end. I can call a ‘set button style’ at the end instead although the target for that doesn’t connect with the ‘as button’ on the cast to button node. I can get a ‘cast to buttonwidgetstyle’ instead as that will go into the ‘set button style’. Thanks for the help by the way, it’s much appreciated