Hi all,
I don’t know how to create widget sliders dynamically.
I want my program to read the number of files in the folder and create the same number of sliders.
For example, I have 5 files in the folder and program create 5 sliders and add to view for player.
And I don’t know how get the sliders value in c++ programm.
Thank you!
There a lot of options you can go for, but first you need to understand how UI works in UE4 so you get some understanding what you can od
The UI system that UE4 uses is called Slate, it was originally made to create UE4 editor UI as old system from UE3 was very messy and not very multi platform friendly and all editor UI you see is Slate.
This system works great that it would be a huge potential loss if oyu can not use that in UE4 games themselves, problem is Slate was designed as quite low level UI system (that also needs to cooperate with OS window system), because of that it does not use UE4 UObjects at it’s core and can not be used in blueprints directly. To solve this problem special UObject wrapper was made called Unreal Motion Graphics (UMG) which allowed to use Slate features in game more easily and with full blueprint support. UMG have wrapper class (UWidget) for each (but not all) Slate widget class (SWidget), it can even contain full Slate widget composition as single UMG Widget.
But Slate is a lot easier to operate in C++ thanks for it quite hackish way to declare widgets which oyu can see here:
So there 3 main paths you can go, either:
- Go full UMG and just make a blueprints nodes to do all the C++ stuff you need. You can easily hook up your entire Widget Blueprint by creating your own UUserWidget class with implementable events which later you can base blueprint with (create Blueprint not Widget Blueprint, UE4 will detect you trying to make a widget blueprint and use proper editor for it)
- 50/50 method by making custom UWidget where you will compose your own Slate widget that then you can place in UMG Blueprint Widget. All you need to do is declere Slate widget in RebuildWidget function and code for it contained in UWidget class UWidget::RebuildWidget | Unreal Engine Documentation Only note here is that if you gonna use properties for widget editor you need to override SychronizeProperties which will be called on every property update and at this function you sync your slate widgets with UMG widget properties UWidget::SynchronizeProperties | Unreal Engine Documentation.
- And finally go Full slate, make you own slate widget like you would do for editor and just make it view at game runtime you can read about it here: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums
option 1 and 2 is better, primerly because it a lot easier to integrate things with blueprints, UMG is also better for UI animations something that base Slate does not have (It suppose to be main feature if UMG as it has “Motion Graphics” in the game) which might be useful. Option 2 more if you want to compose widgets in C++ as Slate declare method is a lot better an cleaner then trying to compose UMG widgets in C++ which was primerly done to be used with Widget Blueprint.