Can you cleanly store Remove from Parent inside of a function?

I have a UI element that needs to disappear every time the player leaves combat. Normally when I need something to happen during the end of combat I stick it in the OutOfCombat function that you can see highlighted. This is useful because there are multiple ways to leave combat.

Now that I’ve added a UI element that needs to vanish I’m having problems. The setup that is screenshotted lets me remove the UI element whenever combat is manually ended. However, if the player sprints, or crouches, etc to exit combat the UI element remains. I tried to stick the “remove from parent” node inside the “OutOfCombat” function but that doesn’t seem to work. Is there an easy way for me to put the remove from parent node inside of the function? The alternative seems to be manually adding the remove node to each instance of out combat which defeats the purpose of having a function in the first place.

It should work as is. Two notes:

  • ensure you store the reference to the widget you remove from parent - otherwise you’ll have it garbage collected and will need to recreate and re-add the widget
  • alternatively, consider not removing it from parent and hide it instead (or collapse if you need something else to occupy the same space in the hierarchy)

Thank you! I wasn’t storing the widget which was my main problem. Now that it’s a variable I can reference it easily inside of the out of combat function. I’m also collapsing it which helps. For anyone who gets here and needs to know what the hide node is, I’m using SetVisibility which is plugged into my widget variable.