How to create a widget and add it to viewport if both conditions are true

the simplest method to accomplish this would be to use a gate as shown below (fist Picture). the gate will control whether key input can go through based on if its open or closed. so if the gates closed your input cant go through, meaning you can press E all you like and you will never show the widget.

A second method you could use would be to enable and disable input to the actor based on the overlap as seen in picture 2. this may be a better method in some cases.

of course theres many other methods that could also be used such as using blueprint interfaces (possibly the best method if you have “use” key, but a bit more complex). you should also note that you may need to change the consume input setting in the details panel depending on which solution you go with. oh and i also added two different types of flow control here for examples sake, in the first picture theres a cast so the gate only opens when a character is overlapping, the second picture is set so the enable input only happens when the player character is overlapping. this extra bit prevents the widget from being created if your not the one who overlapped the widget, for example if you had a tree overlapping the actor and you were halfway across the map and press E the widget wouldnt be created since it wasnt a character overlapping the actor.