I am currently in the process of setting up some pickup items.
So far I have got to the stage where a widget is displayed when the player character overlaps a trigger box and the widget is hidden when the overlap ends.
During the overlap and end overlap events, I am updating a bool variable to track when the widget is displayed and when it is not displayed.
When trying to execute anything based on the value of this variable, it always comes back as false. I have added print strings to my blueprint at the points where I am setting the variable value and it is never set back to false. Despite this whenever I check it after hitting an input key it is always false.
I’ve printed the variable value on a tick event and this shows that it is initially true, then changes to false for several ticks and then goes back to true for one tick. This pattern repeats.
Can anyone see the issue in my blueprints?
You have made a few basic errors in designing your widget and its logic.
I had originally written out a whole thing for this question but it got deleted when I tried to post it.
I suggest watching some tutorials on UMG.
You can use IsVisible on your widget variable.
Thanks for the link. That video is useful for setting up a standard widget for displaying health etc but not so useful for setting up widgets for pickup items that only show when the character is overlapping a box volume.
I will keep searching for videos. I found a few specific to the task at hand but they all had their own issues when testing.
So I have followed another video which gives a much cleaner way of creating and displaying the widget however I am still seeing the same issue as before.
On overlap I set a variable to true.
On end overlap I set it to false.
If I move my character into the trigger volume and print the boolean variable to screen it is constantly switching even though the end overlap event has not been triggered.
Ok so I’m now at the point where I can pickup an item successfully. The issue I have is that I can only pickup the item that I most recently placed in the level. I can then stay on that same item and keep pressing F to pickup all the others.
I would have assumed that every pickup I drop in to the level would run their own blueprint scripts independently however this doesn’t appear to be the case.
Can anyone advise how I properly instance the pickup items?
So turns out that the fix for this was simple.
I added an ‘EnableInput’ node on the begin overlap event and a ‘DisableInput’ node on the end overlap event.
Not entirely how this explains the behaviour I was seeing with different instances of the blueprint actor using each others scripting and meshes.
The problem was that when you were overlapping the object you were only checking if it was the player and a bool that you haven’t set anywhere. You needed to actually set the boolean to either true or false or it will always return as the default value.
Also you only need to call Add to Viewport once after creating the widget. So Create Widget > Set Widget Reference > Add to Viewport. You don’t need it in your hide and show functions. If you need any more help just ask.