Announcement

Collapse
No announcement yet.

Thoughts on how to create linked sliders that control a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Thoughts on how to create linked sliders that control a variable

    I'd like to use UMG to create two sliders: one called Speed and the other Strength. Lets say 1-100 is the range of the sliders, and they both start off at 50. I'd like them to work so that if you change one the other automatically changes as well. As an example; if Speed is at 75, the Strength is automatically set to the 25. Or if you change Strength to 65, then Speed is automatically set to 35, etc.

    Any thoughts on how to achieve that? Thanks!

    #2
    Whenever you change slider1, set it to the actual value and set slider2 to 1 - slider1.value

    So if slider 1 is 65 (or 0.65 in a 1 scale) and 1-0.65 = 0.35 then set slider 2 to be 0.35.
    Procedural, modular, on-the-fly animation - iTween For UE4
    - Actors - Components - UMG - Ease In - Ease Out - Path-constrained Animation - $0

    Runtime Datatable
    -All the fun of DataTables dynamically loaded from text or Google Sheets while your game is running!

    Comment


      #3
      Originally posted by Jared Therriault View Post
      Whenever you change slider1, set it to the actual value and set slider2 to 1 - slider1.value

      So if slider 1 is 65 (or 0.65 in a 1 scale) and 1-0.65 = 0.35 then set slider 2 to be 0.35.
      So "MyCharacter BP" has two Floats: P_Strength and P_Speed. Both are set to .5 (Assuming 1 is the max). Those are public.

      In "MyHUD BP", in the Designer view I have the Strength slider set to .5. I'm not sure if you want me to 'Bind > Create Binding' on the Speed slider? If so, can you give me an idea of what to do within the Binding please? I'm a bit new to BP and UMG...

      Comment


        #4
        Oh no, binding is for event dispatchers. I suppose you could use an event dispatcher here if you wanted to, but I wouldn't.

        Set it up like this (assuming you know absolutely nothing, please forgive me if this seems patronizing):
        Click image for larger version

Name:	Untitled-1.png
Views:	1
Size:	288.1 KB
ID:	1064283

        1. Event Construct - In your widget blueprint, this is the first thing that gets called after the widget is created.
        2. Sequence - Nodes that come out of this are executed one after another
        3. Set Value - This node sets the value of a UMG slider (0->1)
        4. Same as 3
        5. Reference to your character blueprint
        6. Get Speed from your character
        7. Get Strength from your character
        8. A reference to your speed slider
        9. A reference to your strength slider
        10. Reference to your character blueprint, same as 5
        11. A reference to your speed slider, same as 8
        12. A reference to your strength slider, same as 9
        13. OnValueChanged - called whenever a slider's value is changed by the player. Find it in your designer view with your slider selected
        14. Set strength variable from your character
        15. Set speed variable from your character
        16. Math node, 1 minus value from OnValueChanged
        17. Set value of a slider, same as 3 and 4
        18. Same as 13
        19. Same as 15
        20. Same as 14
        21. Math node, 1 minus value from OnValueChanged, same as 16
        22. Same as 3, 4, 17

        When the widget is created (1), set the value of your Speed slider (3, 8) to be the same as your character's (5) Speed (6), assuming it's between 0 and 1. Then set the value of your Strength slider (4, 9) to be the same as your character's (5) Strength (7).

        Then whenever your player changes the strength slider (13), it will set your character's (11) Strength (14) to be the value of said slider (13). Then set your character's (11) Speed (15) to be 1 minus the value of the slider (13, 16) and set the value of the Speed slider to be the same as that (10, 16, 17).

        Finally, whenever your player changes the speed slider (18), it will set your character's (11) Speed (19) to be the value of said slider (18). Then set your character's (11) Strength (20) to be 1 minus the value of the slider (18, 21) and set the value of the Strength slider to be the same as that (12, 21, 22).
        Procedural, modular, on-the-fly animation - iTween For UE4
        - Actors - Components - UMG - Ease In - Ease Out - Path-constrained Animation - $0

        Runtime Datatable
        -All the fun of DataTables dynamically loaded from text or Google Sheets while your game is running!

        Comment


          #5
          Originally posted by Jared Therriault View Post
          Oh no, binding is for event dispatchers...
          Thanks for this! I'll give it a shot later today. I really appreciate it.

          Comment


            #6
            Here's how I would do it, you'd need to do some slightly different math if you want to use whole numbers, I just use the 0..1 range the slider expects. You'd just need to format it in a function by dividing by the Max Int/Str value to get it into normalized space.

            Comment


              #7
              Hi, i ll use this thread to ask something similar ..

              I'm working on a simple project, building an app for Cephalometric analysis lessons. I managed to import my models, and build the UI (UMG), but i'm stuck now. I need to "link" UI sliders to my model morph target.

              For example, when i move Slider one, my model start to morph to morph target one ... Just like a character customization screen.

              I'm not a programmer but in my mind, i need to get the morph target value to a variable and use the slider to increase or decrease this value. Can anyone help me with this ?

              Comment


                #8
                Here my character blueprint screenshot.



                I don't know if i did it right, but i have the SliderValue variable (its should be the umg slider) and the MorphValue (its should be the mesh called Morpher, morph target called morph_01 value), now i'm stuck again

                The HUD is on screen, the mouse cursor is on screen ... all working but can't control the morph target with the slider

                Can someone help ?
                Thanks.
                Attached Files

                Comment


                  #9
                  In your HUD, you should create a handler for the slider value changing, and set your morphers value when it changes. Then you should create a binding for getting the slider value to your morpher's value (normalized 0..1).

                  Comment


                    #10
                    Thank you I'll try to go this way ...

                    Should i remove all i did in the character blueprint (i meaning the slider and morph part) ?
                    I'm not sure if this way to get the morph target value and put in a variable is correct. Is it ?

                    The target is my a BP actor that contain my skeletal mesh with morph target called Morph_01 ... so the only node i found was this one "get morph target" but i not sure if its right to use it this way.

                    Lets say its right, then i put this part on my HUD and bind the slider with the "get morph target" return value variable, MorphValor in this case ?

                    Comment


                      #11
                      Also you need to connect up the Set nodes, right now you are not passing in Exec wires so they are not being called.

                      You need to connect it up similar to this, I used yellow to mark the pins that need to be connected (just make sure all of the Exec inputs are used otherwise it will not work):

                      Click image for larger version

Name:	SliderImage2.PNG
Views:	1
Size:	745.1 KB
ID:	1065991
                      Last edited by DotCam; 02-04-2015, 01:05 PM.
                      Free Community Ocean & Sky Project || Join us on Discord! || Trello Roadmap

                      Comment


                        #12
                        Hello,

                        I tried that way, and result in some errors, and i realize that was the wrong way to do it. Now i set all this way:

                        1- Put the part that create HUD, set input mode UIOnly with mouse enabled in my character blueprint. Its working, i can see the HUD, slider is moving and cursor always on.

                        2- Create an event OnValueChanged for the slider in my HUD widget blueprint, and set this way. Again, i'm not sure if its right but there no more errors on compile.

                        Click image for larger version

Name:	ue401.jpg
Views:	1
Size:	171.0 KB
ID:	1066032

                        Now the slider is moving when playing the game but nothing happening. I added a print string "CAST FAIL" on cast failed, and its failing, maybe i missing something or doing something wrong ... any help ?
                        Last edited by oXR; 02-05-2015, 02:28 PM. Reason: Update

                        Comment


                          #13
                          Hi there,

                          and thats why i always recommend to create UMG Widgets inside the controller class.

                          First: Sure your cast fails -> you dont have any instance of BP_BoxActor given -> so casting NULL into NULL will return in NULL.
                          Second: just because im a bit dainty. Rename your HUD Widget into "HUDWidget" because when i read HUD i dont expect you are talking about a widget (HUD != UMG Widgets)

                          Third: Place your Code (within the Draw UI Comment) into the player controller class why? you need the reference to a player controller anyways.
                          Fourth: (In Player Controller) On Begin Play -> Create Widget -> just to be clear set a reference to "self" to the Owning Player Pin -> Output Pin save in variable (you already do so) and add this reference to viewport
                          Fifth: (In Player Controller) Delete the Get Player Controller node -> you dont need it anymore
                          Sixth: Go inside the widget -> Add a Custom Event or a Function with the input of your incoming morph value -> take this pin to set your widgets variable where your slider reacts to.
                          Seventh: Inside your character -> Add On Begin Play and set your Morph value in the way you did.
                          Eighthly: After the node Add to viewport -> Call Get Character/Controlled Pawn -> Get the Morph value || Get your Widget reference->take the outpin and call you event i mentioned in 6. - connect the value from Character with the call event input.

                          additonal: to set your input node he want your player controller reference and the widgets reference in order to setup it to be active. I even wonder why it doesnt complain about it.

                          if you want you can check: https://www.youtube.com/watch?v=mRRe...AX7IX68A62tolX

                          best regards
                          Live long and prosper.

                          Comment


                            #14
                            Hello again ..

                            I did part of these steps already, 1st step removed all that part, 2nd,3rd,4th,5th done.
                            At 6th step ...Should i create this function by bind at slider value ?? and the return value will be my SliderVal (float variable) ??
                            At 7th step ... you telling me to set the morph target inside my character blueprint, but my character is just a static camera and have no mesh or morph targets ... its an object in the scene that have the mesh and morph targets. So i set 7th step in my object blueprint or still in my character blueprint ??

                            Your videos helped me on how to create these functions. Thanks.

                            Comment


                              #15
                              Hello again !

                              Its all working now ... Thanks everyone

                              here how i set it up:

                              In the controller blueprint.

                              Click image for larger version

Name:	UE01.jpg
Views:	1
Size:	374.0 KB
ID:	1066212

                              In the widget blueprint.

                              Click image for larger version

Name:	UE02.jpg
Views:	1
Size:	351.1 KB
ID:	1066213

                              Its all working this way

                              Comment

                              Working...
                              X