Widget Checkbox question

Hi I have programmed a widget with a checkbox that when ticked it enables a filter that the player unlocks, but when I exit the widget and go back to it the check box is unchecked again. How do I program it to stay checked when exited?

How are you doing it? If you create and then remove a widget from the viewport every time, you create brand new widget instances with fresh data.

That seems to be the case. Do I need to create a Game instance for it?

Not necessarily, create the widget once, reference it. Then simply hide / show it as needed, rather than create / remove. It will retain its data this way.

Oh okay. Is that instead of removing from parent?

You can remove instead of hiding, but ensure to bring back the same widget you had created rather than create one from scratch.

Right I’ve got you now. How would I do that? What Node do I need to use?

If you prefer Removing from viewport rather than hiding:

  • to effortlessly create a reference variable of matching type:

  • to validate a Get node:

That’s great thanks for sending those.

Should you opt for showing / hiding instead since it’s more efficient:

The widget always lives in the viewport and is laid out, we simply toggle its visibility. Note that the widget can remove self / or set own visibility from within, if needed.

One thing I need to ask, do I only need to do this for the widget with the checkbox? I currently have it set up with different widgets for each menu.

That’s up to you. If you want a widget (or actor, or component) to retain data, don’t destroy it and create a new one.

Last thing I wanted to know. Are you able to store widget variable data within game instances also?

This phrase / question does not make much sense, sadly. The Game Instance’s persistance has nothing to do with widget data retention.

In BPs everything is an instance, even singletons are instances.

That’s what I was thinking.