UMG Inventory Tutorial: Cannot Pick Up Items

Well, everything else went off without a hitch as far as I can tell, but I can’t seem to pick up those pesky items for further testing.

This looks a bit weird to me.

Where is your eventdispatcher defined you call PickUpItem with, because right now it refers to the Blueprint you are in right now in your picture which seems not be right.

May i see your all the blueprint flowgraphs you set up, Widget, Character/Controller or whatever you used?

kind regards

Yeah, sorry, I was a bit vague…themore I look at it and realize how hard it is to pin down, the more I believe I botched something or a whole lot of somethings. I do recall running into many errors, not being able to find things with context box checked, etc. Also, the event dispatcher you’re referring to; well, after I found out that things weren’t working I went in and sorta kinda’ accidentally

pushed it into the internal character. Gah…to be honest, I think I’m going to start over from scratch…again, hahah. Thanks for the speedy response…I’ll get it…Eventually.

Ok there are a few things in your game logic which are bothering me.

The things i tell you now, are not meant to be the best solution, but i think this will bring up a little more structure in your game.

I´ll start with the first Picture (Character1):

  • Inputhandling should not be placed inside your character class, there is a reason why a PlayerControllerClass exists.

  • the example BP MyCharacter you see in most tutorials, does not mean this is YOUR character, it could be the only one existing in this world so, but consider to have more than one characters of this class in your game means they will all do something when you fire the TAB input.

  • Find yourself some time and read into software architecture, in this case i would recommend a MVC (Model View Controller) concept, which means, you have Models which are a bunch of Data (f.e. Actors like Items, Character a.s.o, or Widgets), you have a View, which only receive input which tells the View what to show on your monitor (Your HUD!), and at last there is the PlayerController (which has the Architecture-Name “Controller” already in it). This Controller class do the logic for Input.

  • You need to figure out which things really belong to a Character, your are right with the Inventory, the Inventory belongs to a character holding the item´s which belongs to the inventory. For remodelling i would recommend to just add a function into your character class to modify your Inventory (AddItem, DropItem) and to create a GetInventory to receive a reference to it in other classes.

to be continued because i lack time right now

continue

  • Inside your character you refer to your GameHUD widget, again You are not the Character but the PlayerController which holds control over a character or even more to manipulate their behaviour. And Widgets, which holds just structures of how something will look like on your screen (UI´s) have no kind of relationship with a Character. Considering you want to show an Inventory, the widget for that would describe of how your menu will look like, the actual inventorydate (the items you wanna show) are coming from the character.

Workflow: Press Tab tells HUD to set the InventoryWidget to Visible or not. Your create your widget inside the player controller, this widget belongs to the PlayerCharacter now. If you have a multiplayer each possible player will have its own Widgets with each player´s different data to show. Then calling Add to Viewport and give your HUDReference, from GetHUD to your Screen.

To put it together → Your PlayerController has a reference to its Widgets, to the HUD and to its current PlayerCharacterActor.

Your HUD only responds to the commands the PlayerController gives it to show your epic stuff. Im not 100% if you would put the enable Mouse Cursor and Disable Input in HUD or PlayerController right now.

As for the third picture (Character2)

Simple question here:

i have just seen that you get your actual inventory (tell if im wrong) from out of a widget, which seems not to be the place for the “real” Inventory of your Character. The array can be stored in your character and you can add a new variable which is set to the maximal amount of items you can carry. If the amount of items in array are = MaxAmount then fire your message “Inventory is full” or something.

little edit in Character2:
you are inside character. Press X and call the eventdispatcher of AN item, and here lies the problem, you have no reference to an MeatPieItem, even more your are referencing “self” and i dont think you wanna compress your self into your own inventory :wink:

the second picture (MeatPiePickUp)

I assume the following. You run around and if you run over a meatpie it should be added to your inventory when you press X.

Even here you set references to your widget, which is not needed. Another question is here whether you want to have the PickUp Text Widget inside the world (3D-Widget) or on your HUD screen. Btw your RefreshInventory is never been called.

Overlap of PickUp class. Well this is not my speciality. But i would go on like this.

If this Pickup´s overlap is triggered, find out if its the character of the playercontroller (Get PlayerController → Get Player Character). If yes, call a custom event (OnCharacterPickUpOverlap) inside the controller and give the PickUp as reference to the controller and save it. If you press X now, you check if there is an item your character is overlapped with, and this will fire the AddItem to your Characters Inventory. Again, im not sure about this. after the adding you need to empty the itemvariable inside the controller, and if its empty you wont do nothing when pressing X.

To update the correctness of your widgets now you only need to do that in widgets event graph. And adding event dispatchers or an interface with your playercontroller.

Inside the widget you would call GetCharacter, which gets you the current possessed character from playercontroller, get the inventory from it and update your widgetcontent based on the current inventory.

Playercontroller would call RefreshInventory, and your widget will fire again to update its content.

Ok… probably i forgot some things, but i hope this helps you a lot.

Im sorry for the long text, its not my purpose to admonish you in some kind of way but to help you with a better understanding :wink:

btw, i would be happy if you give me a rating, if that helped you :wink:

Oh, thank you! I think this last answer here could save me a lot of work - The part about referencing the meat pie itself. You are correct in that, but, Basically, this is for picking up ANY item that is programmed to be picked up, not just the meat pie. This was supposed to be a basic template that would allow the player to pick up any object by pressing X once the character was in range. How would I tell it to do that?

My inventory slots are represented and married to the widget basically.

you would need to create a parent PickUP Class. This class contains the PickUp action you wish for. And all your pickupItemClasses shall inherit from this one and instantly got the same behaviour as the parent.

I assume this could be working in Blueprint too.

Create a new Blueprint “TestParent” and see if you can create another Blueprint “TestChild” and try to select “TestParent”
as parent class. If yes this should do the magic you wish :wink:

Well, if you do it this way, i can imagine this will end up in bugs, have you only changed the missing pin to the item target reference?

eXi, sure i will thanks for reforming :wink:

Well, I’ve got it to where I can pick up the objects - it was as simple as a single executable pin not being connected where it ought to have been…BUT, now, my inventory is totally broken. Slots greyed out, item image does not get added and doesn’t even act like a button anymore.

Hey, would you mind sticking to comments instead of posting answer by answer? (: Thanks.