Announcement

Collapse
No announcement yet.

Binding C++ variable to UMG widget without updating every tick

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

    Binding C++ variable to UMG widget without updating every tick

    So all of my player data is in a C++ class that I exposed to blueprint. I used get nodes to grab the value of the stats my UI displays, set nodes to assign those values to a variable in blueprint, then used a binding to ensure that whenever that variable changes, the UI updates in turn:

    Values set in main HUD blueprint:
    Click image for larger version

Name:	Card1.png
Views:	1
Size:	59.6 KB
ID:	1159221

    Function run by the property binding hooking the value to the health bar slider's fill percent:
    Click image for larger version

Name:	Card2.png
Views:	1
Size:	74.1 KB
ID:	1159222

    The problem with this setup is that as the player's data changes in the C++ class, the binding fails to update its value on the HUD, as that binding is pointed at a blueprint variable. I don't want to constantly re-acquire that value in the blueprint's event tick, as that would be ludicrously inefficient, is there any way I can give blueprint a pointer to the data, and trust UMG to update itself when the value in that address changes?

    #2
    Hey,

    so these Variables are located in your PlayerCharacterClass, right?

    Why don't you just get the PlayerCharacter directly INSIDE of the binding and instead of setting the HealthValue variable, you dismiss this one and directly
    plug in the result of the division into the ReturnValue.

    You just need to make sure, that the "ReturnNode" is reached in all states. Means: If you cast the PlayerCharacter Return, the "Cast Failed" exec must
    reach the ReturnNode. I normally use a Local Variable for the Return and for all fails (cast, not valid etc) i just fill the variable with a standard value.
    Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

    My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
    (Including 100+ Pages Multiplayer Network Compendium to get you started.)

    Comment


      #3
      Oh hey, that's an excellent idea; the casting is still a bit expensive, but it's massively cheaper than running event tick. For the local variable handling returns, am I correct that I don't even have to Set it to anything, so long as that class's constructor will initialize any needed variables by default?

      Comment


        #4
        If it is a variable that is set to something you want to work with, then yes. If you for example have an FString for this Local Return in the binding Function, then you might want to fill it with "Not available" or something
        like that instead of an empty text. But here it is a float, so you could just not fill it and it will return 0. Or am i misunderstanding something here?
        Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

        My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
        (Including 100+ Pages Multiplayer Network Compendium to get you started.)

        Comment


          #5
          I just finished rewiring everything and this works perfectly- thank you very much for the suggestion

          Comment


            #6
            You're welcome (:
            Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

            My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
            (Including 100+ Pages Multiplayer Network Compendium to get you started.)

            Comment


              #7
              What I do is to instead of calculating the value inside of the binded function, I just bind a variable, and then in a seperate function I calculate the variable, then I call this function whenever I need to update it.
              Marketplace Assets

              Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
              Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
              Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

              Comment

              Working...
              X