UI Generation code executing when it should not.

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

UI/Tools

Summary

When I create the following device and do not call the PlayerSpawned function, the HUD still shows up and does not update properly.

Steps to Reproduce

Paste following code into a device and put the device in an island.

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

A Verse-authored creative device that can be placed in a level

resource_view_device := class(creative_device):

S2M<localizes>(S:string):message="{S}"

@editable PlayerSpawners : []player_spawner_device = array{}
@editable RefreshRate : float = 0.5
@editable ConditButton : conditional_button_device = conditional_button_device{}
@editable ConditButtonTwo : conditional_button_device = conditional_button_device{}
@editable ShowResourceButton : button_device = button_device{}
@editable HUD_Message_device : hud_message_device = hud_message_device{}

var ResourceTextBlockPerAgent : [agent]?text_block = map{}

# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
    for(PS:PlayerSpawners):
        PS.SpawnedEvent.Subscribe(PlayerSpawned)
    ShowResourceButton.InteractedWithEvent.Subscribe(DisplayResourcesInHUD)

DisplayResourcesInHUD(AgentIn: agent): void=
    MyResourcePreLoop := ConditButton.GetItemCount(AgentIn,0)
    MyResourceTwoPreLoop := ConditButtonTwo.GetItemCount(AgentIn,0)
    Print("Resource 1: {MyResourcePreLoop}, Resource 2: {MyResourceTwoPreLoop}")
    HUD_Message_device.SetText(S2M("Gold: {MyResourcePreLoop}\nDiamonds: {MyResourceTwoPreLoop}"))
    HUD_Message_device.Show()



PlayerSpawned(Agent:agent):void=
    Print("Player Spawned")
    if(MyTextBlock:=ResourceTextBlockPerAgent[Agent]?){}
    else:
        AssignUI(Agent)

AssignUI(Agent:agent):void=
    Print("Assigning UI")
    MyCanvas:=MakeCanvas(Agent)
    if:
        PlayerUI:=GetPlayerUI[player[Agent]]
    then:
        Print ("Adding widget to player UI, spawning refresh UI.")
        PlayerUI.AddWidget(MyCanvas)
        spawn{RefreshUI(Agent)}

RefreshUI(Agent:agent)<suspends>:void=
    Print("Starting to Refresh")
    MyResourcePreLoop := ConditButton.GetItemCount(Agent,0)
    MyResourceTwoPreLoop := ConditButtonTwo.GetItemCount(Agent,0)
    Print("Resource 1: {MyResourcePreLoop}, Resource 2: {MyResourceTwoPreLoop}")
    if(TextBlock := ResourceTextBlockPerAgent[Agent]?):
        loop:
            Sleep(RefreshRate)
            MyResource := ConditButton.GetItemCount(Agent,0)
            MyResourceTwo := ConditButtonTwo.GetItemCount(Agent,0)
            TextBlock.SetText(S2M("Gold: {MyResource}\nDiamonds: {MyResourceTwo}"))

MakeCanvas(Agent:agent):canvas=
    Print("Making Canvas")
    MyTextBlock:=text_block:
        DefaultTextColor:=White

    if(set ResourceTextBlockPerAgent[Agent] = option{MyTextBlock}){}

    MyCanvas:=canvas:
        Slots:=array:
            canvas_slot:
                Widget:=MyTextBlock
                Anchors := anchors{ Minimum := vector2{X := 0.8, Y := 0.50}, Maximum := vector2{X := 1.0, Y := 0.5}}
                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                Alignment := vector2{X := 0.0, Y := 0.9}

    return MyCanvas

Expected Result

No UI when the PlayerSpawners editable is empty.

Observed Result

UI when PlayerSpawners editable is empty. When all spawners in the level are hooked up to a different device and PlayerSpawned is subscribed to via that other device, the UI updates and works appropriately. But the UI should not show when the code to generate it for each player is not run.

Platform(s)

PC