Remove or Disable Widget in C++ | RemoveFromParent() and RemoveFromViewPort()

I have a crosshair widget that I am trying to disable when I unequip my weapon. Previously using Blueprints I had the functions Add to Viewport (to enable) and Remove All Widgets (to disable) on each weapon, which worked fine.

Attempting this on C++ there doesn’t seem to be a “Remove all Widgets” function. I have tried RemoveFromParent(), RemoveFromViewPort() and RemoveFromRoot() without any luck.

Above code is giving this result (regarding the crosshairs)

image

The node says the target is “Widget Layout Library”. So using that you can find the C++ RemoveAllWidgets

UWidgetLayoutLibrary::RemoveAllWidgets | Unreal Engine Documentation

Used like so

UWidgetLayoutLibrary::RemoveAllWidgets(this);
2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.