Announcement

Collapse
No announcement yet.

how to get UMG widget casting to Actor component

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

    how to get UMG widget casting to Actor component

    Hi
    I created a player health system that I built inside a character BP, and the UMG widget was casting to that Character BP to get the variables so it could update the health bar stuff.
    But
    I wanted to take it a bit further and make the Health system more modular and reusable by turning it in to a Actor component that I could just add to Any character BP.

    Problem is that I cant seem to cast from the UMG widget to the Actor component, as it not accepting any get owner/Actor, controlled pawn, targets I plugin.

    Sorry I cant provide pictures as I'm at work, But I was hoping somebody could tell me what I have got wrong.
    Last edited by AlphaWolF; 10-09-2019, 04:18 AM.
    Artstation

    #2
    If your widget has a variable that references the required character, you can use the Get Component by Class node to get its health component. Just add an Is Valid check to make sure that the character has a health component and you're good to go.
    NEW: Tower Defense Starter Kit (v2.10) | Proximity Mine Launcher [inspired by Hard Reset] | Grid Creation Systems (v1.2 WIP)

    Comment


      #3
      Ok thanks, I will try this later
      Artstation

      Comment


        #4
        There is problem with all umg widgets. Master (or owner) knows its children, but usually its children that need to read information from master, and it is quite hard to get reference to who owns widget. It would be best when player controller (who owns top level umg widget) set some variables in it and that top level umg sent all information to all child widgets. But as i w rote it is complicated to cast to child widgets or to master widget.

        So to simplify all this, i use game mode (for singleplayer) or player controller (in multiplayer setups). I create dispatcher that sends out events to update umg gui. It is simple "name of widget" and "what to display" dispatcher.

        So for eg. to update hitpoints i trigger dispatcher event with "hitpoint" and "90%". Widget that display hitpoints is hooked to dispatcher, and when it gets "hitpoints" message it will update internal variable that keeps hitpoints.

        Quite simple setup. Best is that i do not need to code all that casting to, finding references etc. for each widget. Every single widget hooks to dispatcher in game mode and has simple branch to compare dispatcher name to its own name.

        Comment

        Working...
        X