How can i improve this?

i’m not that good with functions, how can i improve this?

I have a widget menu, with buttons. I use this as “Setting Menu” when i click a button it deletes all loaded “widgets” before loading one, so it’s not possible to load 50x same widget into a “widget box”.

Is it possible to make this more efficient?

What you’re doing isn’t that inefficient but it would be much neater (and easier to maintain) if you used a Widget Switcher - this way you do not have to spawn/despawn widgets all the time, you do not need to reference anything as well.
Switcher is like having tabs in the browser or separate pages where only one is active at a time. So you can dedicate one page to Graphics, one to Audio and one to Game settings, for example.

Have a look at this very short demonstration and see if it helps at all:

Every time you want to display the specific widget, you create it. So after n clicks, there are n of that class but you only need 1. Create the widgets elsewhere and work with their references.
It does not actually matter for performance, I just mention it as a good practice.
Well, that’s not entirely true, depending on how the widgets are set up. If you save any data to a widget, then create a new one to display, well you see the issue there.

Another solution is to set the Visibility of the widget you do not want to see to Collapsed. Essentially, put Controls, Graphics and Settings in the settings menu Scrollbox manually in the editor. Make the buttons affect their the Visibility of the children only, no need to spawn/despawn them.

Apart from the issues @ste1nar mentioned, you will also want to save the changes somewhere - like Graphics settings. Storing them in the widget itself is not a good idea. Game Instance is not bad, saving them to a Config File/Save Game Object is probably better.

I realized also another problem, i have no idea how to get variables from other blueprints. It’s so stupid that they don’t make this easier by a simple setting build inside the editor that will load specific variables between blueprints… yhhh

I was testing “Cast to” but doesn’t work, i need to get a slider variable into thirdpersoncharacter to set the mouse sensivity… annoying yhhh

Blueprint communication is somewhat unnecessarily complicated. It is truly vital to familiarise with all methods, though. You just can’t get anywhere without passing data to and from.

Direct Communication, Event Dispatchers and Interfaces. You will need all 3 eventually. That’s on top of inheritance and casting that you mentioned. Watching a bunch of tutorials, experimenting, building very small games that work well is a great start.

This 2.5h long video by Zak will save you a lot of head-scratching later on:
edit: also, everything franktech said

There’s actually classes you can use other than GameMode that are made for handling settings. For example, **GameUserSettings **already has video settings and you can easily extend this to have more specific settings for your game. Then, you can get the same object by just calling “GetGameUserSettings”. InputSettings remains mostly accessible to C++ unless you want to rely on a plugin though.

Uh. I mean, yeah. If you just need the functionality of the parent class, that could work (and implicitly does most of the time, and you can call parent class if you need to). But inheriting from the same class as some separate instance does not give you any help with referring to that other instance.

Right, because you need a reference before you can use either of them. The benefit of using either of those is that:
1 (Dispatcher): You can bind to an instance of a known class to receive events that are triggered by that instance- but that instance doesn’t have to “know” about you.
2 (Interface): You can interact with an instance of unknown type without having to cast (at least not explicitly in BP). This makes it so the same code can process multiple classes without needed to handle each case separately.

And, from Slackers:

Multiplayer? Throw all the things people said about GameMode… replace it with GameInstance. Probably not the best solution, but *GameMode *is server-only. GameInstance also is valid through the entire game session, even through map transitions. (Edit): Actually MP automatically means that you’ll have to put far more thought into this- but yeah, for now GI will work OK (/Edit)

As far as widget management itself goes, I am a fan of the widget switcher. However, if you don’t want to use it because it keeps the widgets “live”, then you can use a “NamedSlot”. Basically acts as a placeholder for any given widget, and you can manage your widget just like you do now, except you add/remove it to this slot. This also helps you so that you can have these settings not have to be at the bottom of your scrollbox. You can also just manage visibility. These are all valid options.

Taking the time to familiarize yourself with UE4 will greatly reduce frustration. Learning how to engage with certain parts of the community (timing, formatting, etc) would also reduce frustration. Your question is well formed. Your question (that I could see) in slackers was not. Your call if you ever want to revisit there- but if you ask your question in a better format (even copying over some of the stuff would have been fine) you’ll probably get a better response.

I know where the problem was, i had “Create Widget” on Q button, Problem was that it loaded only when Q was pressed so the “Sensivity Var” didn’t existed (Float=0) untill i clicked “Q” to load the var form the widget.

So i made BeginPlay > (Sequence) > Create Widget.
I made on “Q” Key a Flipflop like befor but this time with Set visibility to the SettingMenuReg Var and it switches between Visible and Hidden :slight_smile:
So far all is working like it should.

My thought is now how to save these “setting”, is it ok when the var is inside the Widget or should it be set inside the Player BP?

It allows you read/write write from/to an *.ini file:

What are inside that ini file? Is it working also for more players and to save it on “server” i need to switch authority?

Yeah, you can’t really cache it. It does a lot more for its settings than just acting as an interface to an ini file.

Game user settings. Basically nothing which determines game rules or state should be in this class. There’s no sense in saving it server-side because if you tried everybody would just overwrite other’s settings.


Ok so settings like Sensivity, Graphics settings and so on, will be client sided. But what about saving things like in RPG? Weapons that a player owns and so on?