# Custom UI / HUD

**URL:** <https://forums.unrealengine.com/t/custom-ui-hud/833768>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [March 30, 2023, 10:35am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768 "2023-03-30T10:35:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [March 30, 2023, 10:35am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/1 "2023-03-30T10:35:27Z")

</div>

So i’ve been looking around for YouTube tutorials and forum post about this topic but its basically no coverage of it.

What my focus right now is to make custom HUD that is interactive with the gameplay, for example healthbar, ammo amount etc. Myself is newbie to the Verse language and I feel that the documentation is not very starter friendly on some topics.

So if someone know how to store the players health in a variable and display in a UI widget etc. Hit me up.

With that said, lets make some buzz about the UI creation in general!

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [March 30, 2023, 11:08am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/2 "2023-03-30T11:08:09Z")

</div>

UPDATE

I managed to store the players health and print it. Now I need to be able to print/ update that to the UI when the health changes. Any ideas how the UI can be updated without the press of a button?

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 1, 2023, 4:35pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/3 "2023-04-01T16:35:50Z")

</div>

UPDATE

I have now managed to make a custom healthbar HUD, It’s not the most stylized atm but its atleast working.

So what I did was taking the players current health, insert it into a UI creation with the canvas. I then put the canvas creation in a updateUI() function which is being called through a loop. I don’t know if this is the best performance option, but for now its working as it should!

Haven’t tried it with multiple players with how it syncs etc. Still PROGRESS! 😃

---

<div class="post-metadata">

**Author:** ![Cray\_Opeta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cray_opeta/32/637656_2.png) [@Cray\_Opeta](https://forums.unrealengine.com/u/Cray_Opeta)\
**Post date:** [April 2, 2023, 8:22am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/4 "2023-04-02T08:22:56Z")

</div>

Hello, could you share this code? I think a lot of people would be interested!

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 2, 2023, 11:45am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/5 "2023-04-02T11:45:37Z")

</div>

Absolutely! It’s kind of chaos, but here it is:

```auto
using { /Verse.org/Simulation }
using { /Verse.org/Colors }
using { /Verse.org/Verse }
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI}

dynamic_text_device := class(creative_device):    

    hud_device : hud_message_device = hud_message_device{}

    var _myIntValue:float = 0.0
    var hudIntValue:float = 0.0
    var _textWiget: text_block = text_block{DefaultTextColor:= color{R:=0.1, G:=1.0, B:=0.1}}

    OnBegin<override>()<suspends>:void=
        # set UI on a player
        var players:[]player = Self.GetPlayspace().GetPlayers()
        if (ValidPlayer := players[0]):
            AddUIToPlayer(ValidPlayer)
        loop:
            Sleep(0.1)
            if(FirstPlayer : player = players[0]):
                if(FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                    set _myIntValue = FortniteCharacter.GetHealth()
                    set hudIntValue = FortniteCharacter.GetHealth()
                    
            UpdateUI()
            if(_myIntValue <= 0.0):
                break

    AddUIToPlayer(Player:agent):void=
        if (PlayerUI := GetPlayerUI[player[Player]]):
            PlayerUI.AddWidget(CreateUI())

    CreateUI() : canvas =        
        UpdateUI()
        # align top center of screen
        ui : canvas = canvas:
            Slots := array:
                canvas_slot:
                    Anchors := anchors{Minimum := vector2{X := 0.0, Y := 1.0}, Maximum := vector2{X := 0.0, Y := 1.0}}
                    Offsets := margin{Top := 0.0, Left := 150.0, Right := 0.0, Bottom := 300.0}
                    Alignment := vector2{X := 0.0, Y := 1.0}
                    SizeToContent := false
                    Widget := _textWiget

        return ui

    UpdateUI():void=
        _textWiget.SetText(SetDynamicText(_myIntValue))
        hud_device.SetText(SetDynamicTextHud(hudIntValue))

    SetDynamicText<localizes>(IntValue:float) : message = "HEALTH {IntValue} / 100"
    SetDynamicTextHud<localizes>(hudInt:float) : message = "Dynamic text {hudInt}"

```

I believe the ‘hudIntValue’ can be removed, something i was working on but later scratched

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 2, 2023, 11:49am UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/6 "2023-04-02T11:49:35Z")

</div>

What I haven’t figured out is how to turn that float into a int, so now the health is like 100.0000/100, if you know please tell me haha

---

<div class="post-metadata">

**Author:** ![Cray\_Opeta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cray_opeta/32/637656_2.png) [@Cray\_Opeta](https://forums.unrealengine.com/u/Cray_Opeta)\
**Post date:** [April 2, 2023, 12:01pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/7 "2023-04-02T12:01:30Z")

</div>

There is the Ceil (up), Floor (down) and Round (nearest integer) function to round a number.

This turns the float into an int

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 2, 2023, 12:22pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/8 "2023-04-02T12:22:46Z")

</div>

yeah i’ve tried that but I guess im doing something wrong, how could i do that in the code?

---

<div class="post-metadata">

**Author:** ![Cray\_Opeta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cray_opeta/32/637656_2.png) [@Cray\_Opeta](https://forums.unrealengine.com/u/Cray_Opeta)\
**Post date:** [April 2, 2023, 12:25pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/9 "2023-04-02T12:25:29Z")

</div>

I made a snippet for this  
[Rounding a number | Epic Developer Community (epicgames.com)](https://dev.epicgames.com/community/snippets/opA/fortnite-rounding-a-number)

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 2, 2023, 2:02pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/10 "2023-04-02T14:02:22Z")

</div>

Ah perfect, got it working!

---

<div class="post-metadata">

**Author:** ![DomZaddy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DomZaddy](https://forums.unrealengine.com/u/DomZaddy)\
**Post date:** [April 8, 2023, 1:16pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/11 "2023-04-08T13:16:31Z")

</div>

How did you get it to change man @crazeryn? It might be that my brain is just fried but I can’t make sense of Cray\_Opeta’s snippet.

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 8, 2023, 6:58pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/12 "2023-04-08T18:58:21Z")

</div>

The healthbar to change or from float to integer?

---

<div class="post-metadata">

**Author:** ![DomZaddy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DomZaddy](https://forums.unrealengine.com/u/DomZaddy)\
**Post date:** [April 8, 2023, 8:05pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/13 "2023-04-08T20:05:13Z")

</div>

yesssss pls @crazeryn

---

<div class="post-metadata">

**Author:** ![crazeryn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@crazeryn](https://forums.unrealengine.com/u/crazeryn)\
**Post date:** [April 8, 2023, 11:06pm UTC](https://forums.unrealengine.com/t/custom-ui-hud/833768/14 "2023-04-08T23:06:47Z")

</div>

The new full code:

```auto
using { /Verse.org/Simulation }
using { /Verse.org/Colors }
using { /Verse.org/Verse }
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI}

dynamic_text_device := class(creative_device):    

    hud_device : hud_message_device = hud_message_device{}

    var _myIntValue:float = 0.0
    var numberone:int = 0
    var hudIntValue:float = 0.0
    var _textWiget: text_block = text_block{DefaultTextColor:= color{R:=0.1, G:=1.0, B:=0.1}}

    OnBegin<override>()<suspends>:void=
        # set UI on a player
        var players:[]player = Self.GetPlayspace().GetPlayers()
        if (ValidPlayer := players[0]):
            AddUIToPlayer(ValidPlayer)
        loop:
            Sleep(0.1)
            if(FirstPlayer : player = players[0]):
                if(FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                    set _myIntValue = FortniteCharacter.GetHealth()
                    set hudIntValue = FortniteCharacter.GetHealth()
                    if (number := Round[_myIntValue]):
                        set numberone = number
                        
                    
            UpdateUI()
            if(numberone <= 0):
                break

    AddUIToPlayer(Player:agent):void=
        if (PlayerUI := GetPlayerUI[player[Player]]):
            PlayerUI.AddWidget(CreateUI())

    CreateUI() : canvas =        
        UpdateUI()
        # align top center of screen
        ui : canvas = canvas:
            Slots := array:
                canvas_slot:
                    Anchors := anchors{Minimum := vector2{X := 0.0, Y := 1.0}, Maximum := vector2{X := 0.0, Y := 1.0}}
                    Offsets := margin{Top := 0.0, Left := 150.0, Right := 0.0, Bottom := 300.0}
                    Alignment := vector2{X := 0.0, Y := 1.0}
                    SizeToContent := false
                    Widget := _textWiget

        return ui

    UpdateUI():void=
        _textWiget.SetText(SetDynamicText(numberone))
        hud_device.SetText(SetDynamicTextHud(hudIntValue))

    SetDynamicText<localizes>(IntValue:int) : message = "HEALTH {IntValue} / 100"
    SetDynamicTextHud<localizes>(hudInt:float) : message = "Dynamic text {hudInt}"

```

It is including the convert from float to integer
