Verse Library verse

01 Fragment

Syncs a device counter to a UMG widget using ViewModels for automatic UI updates.

verse-library/using-the-viewmodel-in-umg/01-fragment.verse

# This is a simple Verse script to increment the tracker
# It doesn't touch the UI directly; the ViewModel handles that!

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# Define the device we want to control
type KillCounterDevice = extends TrackerDevice {
}

# This function runs when the game starts
OnBegin<override>()<suspends>: void = {
    # We don't need to manually update the UI.
    # The ViewModel is already listening to this device.
    # Just change the device's value, and the UI follows.
    
    # Example: Set initial value
    SetCurrent(0)
}

# A simple function to add a kill
AddKill(): void = {
    # Get current value
    current := GetCurrent()
    # Add 1
    SetCurrent(current + 1)
    # The ViewModel automatically catches this change
    # and updates the UMG widget via the binding.
}

Comments

    Sign in to vote, comment, or suggest an edit. Sign in