Announcement

Collapse
No announcement yet.

Adding HUD elements through script

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

    Adding HUD elements through script

    Does anyone know how to add, remove, and manipulate elements in a HUD through blueprint?

    #2
    Use Create Widget node to dynamically spawn an UI element; add it to the viewport or add it to an existing container.

    Removing is usually handled by the Remove From Parent node or by adding an element to another container.

    To manipulate them, create direct references, expose UI elements as variables, use dispatchers and events - this is a very broad topic. Widgets can be animated, too.

    More info:
    https://docs.unrealengine.com/en-US/...ide/index.html
    Last edited by Everynone; 11-23-2019, 08:29 PM. Reason: added better link

    Comment


      #3
      Originally posted by Everynone View Post
      Use Create Widget node to dynamically spawn an UI element; add it to the viewport or add it to an existing container.

      More info:

      https://docs.unrealengine.com/en-US/...ets/index.html

      Removing is usually handled by Remove From Parent node or by adding an element to another container.

      To manipulate them, create direct references, expose UI elements as variables, use dispatchers and events - this is a very broad topic. Widgets can be animated, too.
      What I am trying to do is say, add and remove individual elements, such as text or images within the same HUD. The elements would not be preexisting in the HUD. Would this work for that.

      Comment


        #4
        Yes, but you'd need to wrap them in user widgets first.

        Essentially, create a widget with a TextBlock only, for example - expose whatever functionality you'd require from it and then create those widgets on the fly - as a bonus this allows you to maintain code better.

        Comment


          #5
          Originally posted by Everynone View Post
          Yes, but you'd need to wrap them in user widgets first.

          Essentially, create a widget with a TextBlock only, for example - expose whatever functionality you'd require from it and then create those widgets on the fly - as a bonus this allows you to maintain code better.
          So the text block already needs to be there, there's no add text block to widget "****" node or anything like that ?

          Comment


            #6
            No, it does not need to be there. You create a user widget and then dynamically add those widgets during run-time.

            there's no add text block to widget
            In bluerprints this is handled by user widgets. One cannot add native elements directly.

            Comment


              #7
              Originally posted by Everynone View Post
              No, it does not need to be there. You create a user widget and then dynamically add those widgets during run-time.
              Ok so let me make sure I'm getting this right. So I create the widget blueprint, then adding no elements in that specific blueprint, I move into my players blueprint. Then I use the create widget node,select my widget and then store the widget in a variable. So there is a way to use that variable to add and remove things like text blocks and images?

              Comment


                #8
                - create a widget that will represent a list of items the player owns - the list is empty
                - create a widget that will represent an item in the list - a User Widget with just an image
                - during gameplay, you can populate the list with the above-mentioned User Widgets

                What you contain within that user widget is up to you - it can be another super complex menu or a piece of text, or a single image.

                Comment


                  #9
                  I like to make animations in my hud widget for the elements (buttons, text, etc..)

                  You can keep a button off screen and invisible, Move it on screen and change visibility, size whatever. Pretty easy to learn the track editor, they are simple anims.

                  Then you just play an anim from wherever. Your map bp with a trigger box, player bp (if they take dmg).... Whatever the easiest trigger is can send to the widget and play the anim.

                  for example:
                  This is in my menu widget (but could be player hud)
                  This is checked on tick (I need to change that).
                  If my var in my game instance reaches a number a map is unlocked. But really all it does is play an animation that moves a button onto the screen that the player can use when they get back to the menu. That button could be a progress bar or text...

                  Click image for larger version

Name:	PlayAnim.jpg
Views:	89
Size:	132.4 KB
ID:	1690502

                  Comment

                  Working...
                  X