How do I Show a UI Widget and Update it to Every Player in game

Hello! I’m making a Boss Battle and I found this tutorial online with this code Code for boss fight and health bar in UEFN and Verse · GitHub

It works fine but when I try to give the UI to multiple players things stop working.
The health bar doesn’t update and only 1 player can see the working health bar.

I use for loop to get all players and give each player the UI.

Like

    AllPlayers := GetPlayspace().GetPlayers()
    
    for (X := 0..16):
    if (Player := AllPlayers[X]):
        BossHPBar.ShowUIForPlayer(Player) 

Every player can see the boss health bar but it doesnt update when the boss is hit.

This is the map code if you want to check the bug for yourself lol 4085-2886-5650

I would appreciate the help! :slight_smile:

1 Like

Did you ever get an answer? I tried it a similar way and couldn’t get it working… yet.

I can’t figure out why this doesn’t display it for all players. Rather, it shows it to just one player.

image

I found it by myself, you have to make an UI class then a Map for that UI Class

var UIManagerMap : [player]UIManager = map {}

UIManager := class():

Player: player
Agent: agent

var Canvas<internal> : canvas = canvas{}

block:
    set Canvas = canvas:
        Slots := array:
            canvas_slot:
                Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.1}, Maximum := vector2{X := 0.5, Y := 0.1}}
                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                Alignment := vector2{X := 0.5, Y := 0.5}
                Widget := overlay:
                    Slots := array:
                        overlay_slot:
                            Widget := color_block:
                                DefaultColor := NamedColors.Blue
                                DefaultOpacity := 0.7
                                DefaultDesiredSize := vector2{X := 256.0, Y := 128.0}
                        overlay_slot:
                            Widget := stack_box:
                                Orientation := orientation.Vertical
                                Slots := array:
                                    stack_box_slot:
                                        Widget := JumpTextWidget
                                    stack_box_slot:
                                        Widget := DiamondTextWidget


JumpText<private><localizes>(JText : string) : message = "Gas: {JText}"
DiamondText<private><localizes>(DText : string) : message = "Diamonds: {DText}"   
                                              

JumpTextWidget:text_block = text_block{
    DefaultShadowColor := MakeColorFromHex("#000000")
    DefaultShadowOffset := option{vector2{X:= 0.5, Y:= 0.5}} 
    DefaultTextColor := MakeColorFromHex("#FFFFFF")
}   

DiamondTextWidget:text_block = text_block{
    DefaultShadowColor := MakeColorFromHex("#000000")
    DefaultShadowOffset := option{vector2{X:= 0.5, Y:= 0.5}} 
    DefaultTextColor := MakeColorFromHex("#00FFFF")
} 


UpdateUI(Jump: int, Diamond: int): void=
        #update ui
        JumpTextWidget.SetText(JumpText("{Jump}"))
        DiamondTextWidget.SetText(DiamondText("{Diamond}"))

        #set shadow to text
        JumpTextWidget.SetShadowOpacity(1.0)
        DiamondTextWidget.SetShadowOpacity(1.0)

Then you need to show each UI class to each player

if(MyUIMap := UIManagerMap[Player], PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(MyUIMap.Canvas)
Print(“ADDED CANVAS”)

1 Like

Thanks for the info.

I sort of came to that conclusion as well. What I found was that I had to generate a different canvas for each player in order to get it to display to the players. Once I figured that out I figured I was going to have to dedicated a class to this functionality. I started down this road but I think what you just showed is a far more simplistic (meant to read ‘elegant’) way. I will be giving your way a shot.

Thanks a lot of responding and for doing so quickly!

1 Like

Sorry fo the nooby question but where do you place this in your code ?

if(MyUIMap := UIManagerMap[Player], PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(MyUIMap.Canvas)
Print(“ADDED CANVAS”)
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.