I created a check to see if an instance of a widget already exists. The instance comes from setting a variable to save the instance of the widget. However, when I run the check to see if it already exists (and then to remove it) it doesn’t seem to work. I still have widgets stacking on top of each other. Thoughts?
I’m not completely sure what you’re trying to do…
Then executes everything in the same frame. What you’ve done here is just remove everything from the viewport, create another instance, and put that on screen- all on the same frame- this doesn’t actually do anything.
Maybe what you’re thinking of is a FlipFlop- where it’ll alternate between two things every time it’s called.
Keep in mind that widgets don’t get deleted- remove from parent just removes them from the screen. You’ll want to use IsInViewport rather than IsValid. Don’t create another inventory widget, just add it back to the viewport.
VehicleInfoScreen is only removed if inventory is in viewport AND VehicleInfoScreen is also in the viewport. Make sure the false result of InventoryScreen IsInViewport ALSO leads to the VehicleInfoScreen branch check. That’s likely what’s causing your stacking problem- even if VehicleInfoScreen should be removed, it isn’t since InventoryScreen isn’t valid.
I’ve tried your suggestion of using “is in viewport” and it does not help the problem. The issue is that I have a menu that I want to be able to click individual buttons on to bring up the next widget, but I don’t want the widgets to stack, rather, I want the old one to go away.
Unfortunately, every time I hit a different icon, the widgets keeps appearing over top of each other until there are piles and piles of them.
This isn’t a bug or anything- it’s just a lack of feature. Every single button has a reference to their own inventory- there’s nothing removing the active widget when another gets activated.
Create a variable in whatever owns all of the vehicle buttons for the ActiveInventoryWidget. You’ll also want to pass in a reference to this parent when creating the vehicle buttons.
Then replace this entire section with a node to remove the ActiveInventoryWidget from the viewport.
Here you will need to first check if that’s valid since it might not be. You can just check if it’s valid- if it’s valid, it’ll be on screen in this case.
Then, instead of this part, create an inventory if our local inventory isn’t valid, add it to the viewport, and set the previously mentioned “ActiveInventoryWidget” to our local inventory widget.
In all honesty, I only understand about half of what you’re suggesting I do. I’m still pretty new to all of this. I’m not sure why, upon creating the widget, I wouldn’t be able to simply store an instance of it as a a variable, like is done here:
And the check for that stored widget and remove it from parent like here:
But this doesn’t work at all. Widgets have been the bane of my existence since I started on Unreal.
I have found the issue. I simply needed to search for an active instance of the widget before creating a new one, but I was going about it in a complicated way. It is much simpler to get all widgets of class and, if valid, remove them from parent. Thanks for the help everyone.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.