I click the buy button in a widget and destroy the clicked button. It reappears when i open the widget again, how do i keep it away permanently?

Hi all

I have multiple widgets in my game, including a menu for things to buy.
When i buy an item, it makes the button disappear using the “remove from parent” node.
However, when i open up the menu again, the button reappears, allowing the player to buy it a second time

Is there a way to make a button stay in a “on” state? Or for the widget to save its changes after closing it, so it stays the the way you left it so you can come back to it later?

bumpalumpy

Do you delete the Widget or just make it invisible?

I used the “remove from parent” node. i couldnt see a “destroy” node for it

then u probably created it from a wrong node. Try to find “Hide Actor” or “Hide Widget”, like that the widget is still there but invisible

Rather than removing the button, you should bind it’s IsEnabled value to a function or bool variable. So if the button should be enabled you just set your bButtonEnabled bool to true, and if it shouldn’t be, set it to false. You could make the variable exposed on spawn too if you want, so when you create the widget you can pass that variable in.

A function would probable be more useful though. What controls whether the button should be clickable or not? Whatever it is, add it in the form of a function and bind it to IsEnabled. The button will be greyed out and unclickable if your function returns false.

It’s found here:

130147-isenabled.png

(As an aside - from a UX point of view, removing a button isn’t ideal, if a button should not be clickable to a user in certain cases, it should still be visible, just greyed out. Most users will find this more clear than a button suddenly vanishing, they will know there is a reason they can’t access this option. The IsEnabled bool will do this for you.)

Hi Mosel3y

Thanks for the tip, followed your instructions and that looks far better than the button vanishing completely :slight_smile:

However the main problem still remains. If i click the button, it greys out and becomes “disabled” the way it should, but whenever i leave the menu and return to it later, the button is enabled again.

How would i save the status of the button so the widget doesn’t reset it to enabled every time i enter the menu? This is what i’m using.

At the moment your function is always returning true, so yeah, it will always be enabled when it’s opened.

When should the button be enabled? It’s reliant on some other variable in your game. In your case, it’s if the player has upgraded a worker, is it? So, when your player does that, set a bool in your player such as bWorkerUpgraded, to true.

Then, OnConstruct in your widget, get you player character and cast to your character class, get this bool you added, and set the enabled state of the button from this. This is just a simple method, but it should give you some ideas.

You can remove the binding on is enabled now too, it won’t need it if you do it this way.

IT WORKS!!

thank you so much, i have been stuck on this for literally 2 weeks, ive tried so many tutorials and work arounds and nothing has worked, you are a hero

i am facing same issue and this post is old and screenshots are gone is there any chance you can help me on how did you do it im still new to unreal screenshot will help if you can please

Create the widget once, do not recreate every time you want to display it. Once created, store its reference and use it to show / hide it:

This way, if something in the widget was changed (a button was hidden), when you show the widget again, that hidden button will remain hidden.

thanks alot much appreciated <3 im glad people are there to help even for old post i thought i lost hope thanks alot