Quick way to display text to player's screen from Verse script

I just want to display a message on the players screen for a few seconds, like “Your 4th elimination!” or “You need one more kill!”. Is there an already baked interface to do that without getting too fancy?

You can use HUD Message Devices for that.

Thank you. I’m trying to set the message in my Verse script, apparently you can’t pass a direct string, nor directly create a message object. So I’m just trying to figure that out now…

     HUDMessageDevice.SetText("Eliminations for this phase: {PlayerElimsForCurrentPhase}")
        HUDMessageDevice.Show()

So, it looks like I can set a text value in the UEFN editor for the hud_message_device, and that works. But I have no way to dynamically insert a number into that text (which I calculate in Verse). Unless I created a different hud_message_device for every possible number I’d want to display…which would be bad.

Here is an example of displaying dynamic text on the screen, changing a value, and updating the text.

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

dynamic_text_device := class(creative_device):    

    var _myIntValue:int = 0
    var _textWiget: text_block = text_block{DefaultTextColor:= color{R:=1.0, G:=1.0, B:=1.0}}

    OnBegin<override>()<suspends>:void=
        # set UI on a player
        var players:[]player = Self.GetPlayspace().GetPlayers()
        if (ValidPlayer := players[0]):
            AddUIToPlayer(ValidPlayer)

        Sleep(5.0)

        # change values, update UI
        set _myIntValue = 12345
        UpdateUI()

    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.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0} }
                    Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                    Alignment := vector2{X := 0.5, Y := 0.0}
                    SizeToContent := true
                    Widget := _textWiget

        return ui

    UpdateUI():void=
        _textWiget.SetText(SetDynamicText(_myIntValue))

    SetDynamicText<localizes>(IntValue:int) : message = "Dynamic text {IntValue}"
5 Likes

This was awesome. I was even able to get my existing code to work just by using your ‘localizes’ function!

4 Likes

Does anyone know how to structure the line of code to turn off the display text once it is done? I see there is a Set Visibility and widget_visibility option but how to set it up is the question? Thank you.