Widget is Adding Itself Over and Over and Giving Error

I have the Use_Item widget and it is working wonderfully. I have it set to, on Construct, set a variable that if the base has no tower says “Hold E to Customize this Empty Base”, otherwise says “Hold E to Customize [Tower Name] at [Base Name] Base”. My issue arises during testing. I test and get the use item screen to appear and disappear by both looking at the Base and away, and by opening the Base’s menu and closing it. On end play, it gives me 2 warnings with yellow “!” next to them that say “The widget “Use_Item_C” was already added to the screen.”

The BP is a bit elaborate to show in pictures, but basically it does a line trace every frame at a distance of 420uu/cm, and if it hits a buildable it runs the script to see if there is a tower or not and adds the use widget. In the BP code, if the widget is in the viewport, but the player is not focussed on it it removes the UI, but if the player is focussed on it and it is hidden, it will add it. It runs both the “Is Valid” and “Is In Viewport” nodes on a variable called “UI: Pickup” (set on widget Creation and set to null after destroying widget) before adding the widget to the viewport, and in fact I have now connected all pins that used to lead to “Add to Viewport”, to the Branch node with the Valid and In Viewport checker. I have checked over and over and this is the only place that adds this widget to the screen. On top of that, I have had the engine print “Hello” when “Add to Viewport” is called, and it only added it when I wanted and I got no extra “Hello” that should not have been there. Even then, it gives me the warnings. Anyone know what might be going on? I don’t want this to cause any issues or cause bugs in the release.

Below are a few pics that may help explain.



These are the warnings I am getting.



This is where is decides whether to add or remove the Use Item UI from the viewport.



This is where it decides what the Text that the player sees should be.



This is my script for all of the pins to lead to that checks to ensure that the widget is not in the screen before adding, and also shows the variable that I use.

Did you found a solution ?

It seems that you are creating the widget every time. You do not need to do that.
Do this to save a reference to the widget the first time it is created. Only one instance of the widget will be created. Which is nice.

cheers
podge

1 Like