Line trace pick up pop up (press X to pick up)

I’m trying to create a pick up pop up system similar to the one in oblivion and skyrim, by that I mean when the player looks at an object, a pop up will appear saying “press X to pick up” on the screen. I’ve set up a pick up system already, and I’ve created the widget blueprint need for the pop up. I made a simple line trace that is constantly casting a line, and I’ve set up a hit cast so that when the line trace hits an object that the player can pick up, the widget appears on the screen right where I want it, but what I’m having issues with is finding a way to remove the widge off of the screen when the player isn’t looking at the item anymore.

I hope this makes sense, but just to make sure it does, when I play my game the widge doesn’t appear on the screen(which is good!) I can walk the character over to the item and look at it and then the widget appears(which is good as well!) but when I look away the widget is still on the screen (this is what I need help with) I need the widget to go away when the player is not looking at the item

When you are adding widget to the screen firstly , save widgets reference like this

and when trace result will null. remove this widget from view port. with this function

64280-widget.png

Hey thanks for replying

I’m still pretty new to unreal engine, so I’m not exactly sure where everything goes

On my line trace that I have set up, I added a cast to BP_masteritem from the input and the hit input, then I added in a variable that’s linked to my BP_masteritem then I put add to view port. Is that the same as your first screen shot?

Also the remove from parent, where exactly does that go?

you are doing everything good but , when you are making line trace and casting as bp_masteritem if it casts successfully you are adding widget to view port. But if it goes fail you must add this function there and remove this widget from Parent.

On the cast BP_masteritem, I put a string on the “if cast fails” input just to show myself that it is failing when the player isn’t looking at the item, I then put in the function remove from parent like you showed me with the widget variable as the target.

When I play the game the string prints every frame like it should when the player isn’t looking at the item, and then stops printing when it looks at the item, it then prints again after I look away from the item, but I’m still having the same issue with the widget staying on the screen, I must be missing something?

Can you take a picture your code where are you doing line trace please

the line trace is in the MyCharacter blueprint

Is that the correct way for adding the remove from parent? Am I missing any other steps at all?

There is one mistake. You are creating widget each time you are making line trace. So You need on Event begin play Create reference on widget just once . Then when line trace hits your pickup item you need to check if widget is already on screen and if it’s not you need to add to the viewport . Then if item is not your pickup you need to remove widget from the viewport.
I have marked that part need to remove and make this like on second picture.

Okay so I create the bottom picture separately under neither my original code and then delete the code that is high lighted in red. How would I create a reference on widge just once? Is there a node for that, or does that bottom picture include that? Also, to check if the widge is on screen what would I have to do exactly, I’m assuming I would have to set up a series of branch nodes?

  1. Second picture show that you are creating reference and saving.

  2. Check if widget is on screen means if you have already added widget on viewport. To detect this you need to save this in custom bool variable after adding or removing widget from viewport.

  3. I think you have done everything good but there is some mistakes which we must correct.


So do this things and i will show you how to fix this,

i forgot to mention that the line trace is a function inside Mycharacter blueprint, i did that to organize things, would that make a difference?

also, how exactly would i create a bool variable to detect if the widget is on screen or not? I’m pretty new at this so i don’t know exactly where to begin

in the event graph i have a event tick that drags off to the interaction AID function which has my line trace

Just copy everything except class names

  1. Your character add this function on begin play

  1. Then Add bool variable to your widget blueprint and make public also

  1. Then change your line trace with this

everything works perfectly now! thank you so much for your help!