No announcement yet.

I need help with UMG focus and Dropping Items

  • Filter
  • Time
  • Show
Clear All
new posts

    I need help with UMG focus and Dropping Items

    I have an inventory system going. I implemented all the logic I could, but I have met my match.

    I have my inventory stored as a variable on my Main Player Character.

    From there My Inventory Widget pulls the info and I section it off into separate "windows" in the designer where I change visibility based on button presses.

    I can nicely go through the sections and view the items which are loaded based on a class name in the item structure.

    When i start dropping items, they will ALL drop one at a time whether or not i have focus on the items button or not. It will empther the entire inventory, til nothing is left.

    Can you help me find where I am messing this up?

    Not sure that's enough to understand whats going on. Let along tell you what is wrong.

    First thing I can note is that your input node in the character is called twice. This can obviously lead to issues...

    the second thing is that your food item widget is doing stuff on event tick.
    Is this necessary? Can you not change it to call in the functions/events as needed instead?

    I assume that the widget is being added to the container widget at runtime. since that's the only way that you could remove by index.
    are you sure the reference you are using for this is correct?


      Ahh Hmmm should I branch the double input then?

      I really didn't want to event tick the check of the focus. I am a newb i started using unreal a few weeks ago. How would i make sure which item is in focus?

      I am using an event begin play to add the main inventory widget to the viewport. I can screen shot that section.



        i've started redoing the input action button and just using checks to know when to do specific actions with th eone button.

        Thanks for the advice!
        Attached Files


          For the focus. the input should have an OnFocus event of some sort. Let me check.
          Click image for larger version

Name:	UMGButtonEvents.png
Views:	108
Size:	10.3 KB
ID:	1775289
          That's the default for a UMG button.

          Create a custom widget - I think you already have it.
          You usually want this minimal - just the button and a text you can set. Make the buttom stretch to cover the whole canvas. the size is handled by parenting it.

          click on the + button for hovered and you'll create a self contained event.
          Any button that you later add to the UI will be able to use it's own pre-created hover and unhovered functions, which is better then OnFocus since that only happens when the button has either keyboard focus or mouse focus from a direct click.

          You have something like this. probably done with an array
          Click image for larger version

Name:	umgexample.png
Views:	38
Size:	192.0 KB
ID:	1775290
          That should allow you to handle per-instance functions on the button. Including what happens OnClick.
          You can override it with custom event dispatchers.

          Click the + on the OnClick to create the event, and create a custom event dispatcher to call when that button is clicked.
          Add in whatever variables you think you will need - such as a reference to self maybe.

          From the CreateWidget you can then bind to the custom event you created.
          Let's walk through that in an example just cuz I always have trouble with that myself.

          Add the Event Dispatecher in the bottom left normally.
          Add an Input to it, make the variable type an Object and pick reference.

          Compile and save it.

          In the BP that adds the widgets you can now add a binding.
          Drag off the return value of the test widget and type Bind. You should see options for your custom dispatcher.
          It will give you a node with a Red Square - an event reference.

          Drag off the red square and simply click "Add Custom Event". The inputs and information should be automatically matched - if it's not you forgot to compile.
          From then on, you need to cast to the widget to access it's variables. You can use a PureCast since there is no way that the object reference can be wrong.
          Click image for larger version

Name:	example.png
Views:	43
Size:	176.5 KB
ID:	1775291

          Now, with just that, the event is not actually fired. You need to bind the event to the custom event.
          Back in the widget for the button you add a call to it like this.
          Click image for larger version

Name:	customdispatecer.png
Views:	47
Size:	31.3 KB
ID:	1775292

          Im my example the Custom Hover dispatcher is now called any time the button is hovered.
          But the code above will only have anything happen for the first button instance, which has the custom binding.
          And you get something like this here (text was changed otherwise DEF would match)

          Last edited by MostHost LA; 06-12-2020, 08:07 PM.


            Okay Let me absorb all of this and give it a shot, and I will get back. Thanks so much for taking the time to help! I understand everything you wrote, I just need to implement it and see it in action. THANK YOU! I will get back to you asap!


              I think I found a solution. When setting the has focus, I never implemented the OBJECT that had focus. I was focusing on the Items Index to have focus (not logical). Since there was no actual object getting focus it was just focusing on any available index integer.

              I passed the button object as a reference to the inventory and set a branch check to see if the button that was getting focus(hover) was actually hovered/focused. EUREKA!

              Your explanation of the hover helped me figure out I was never setting the object hover/focus status! Thanks a million!
              Attached Files
              Last edited by MindfieldsTech; 06-13-2020, 12:52 PM.