So I am trying to make that when you aim, a crosshair would appear and when you release the button I want it to disappear. The problem is that I only found a way how to remove all widgets, but that would be bad later in the future for the HUD.
Any ideas how to remove just the specific crosshair hud? Thanks in advance
“Create Hud” is a method on your third person character blueprint.
Thus, you need to add a “Remove Hud” method on that same blueprint.
In the “create” method, store the user widget you actually create and add to the viewport.
In the “remove” method, look at that stored widget, and remove that from the viewport, then set the variable to None so you know it’s not active anymore.
An alternative is to create a new variable called “TheCrosshair” on your character. Make it take a reference to a Maincrosshair Widget class. After the “Create Maincrosshair Widget” node, take the return value and assign to that TheCrosshair variable, before you attach it to the viewport.
Then, create a “Remove Hud” method in the same blueprint as creates the widget, and make it get the value of TheCrosshair and pass it to “Remove from Parent”
The way you found will work, too, as long as you don’t need a permanent reference to the widget. (You may want to change crosshair colors, draw charge-meters, or whatnot, depending on game mechanics – but solve that when and if you need it!)
In the new Version you use Remove from Parent (its basically the same as remove from Viewport) you need your UMG the same variable you add to your viewport