Removing Widget on Screen

If you remove the widget from the viewport and do not store the reference, you will have it (and everything in it) destroyed by garbage collection.

Consider the following:

When you hit Tab for the first time, you have no widget - it’s Not Valid, so a widget will be created, reference stored, it’s made Visible and gets added to the Viewport.

Next time we hit Tab, the widget isValid, we switch between visibility states.

However, in most cases, it makes more sense to do this:

Create the inventory when the game starts and then simply show / hide it. What if the player runs into a pickable item before even opening the inventory? They will have no place to store it. I’m simplifying here but it’s worth considering.

So basically i want to press the Tab key to bring and close the inventory widget. My thought is that in my character BP event graph, on press, check if the widget is on screen, if not, create i, else, remove it. But with the following implementation, I have this “Accessed none trying to read property InventoryWidget”, can someone explain why and what should I do to fix this?

Check [Is Valid] instead of [Is Visible]. You’re trying to check the visibility of a widget that doesn’t exist.

Clean! Now it’s working beautifully, thank you!