Verse Library verse

01 Fragment

Binds player health data to a UMG widget via a ViewModel for dynamic HUD updates.

verse-library/using-the-viewmodel-in-umg-in-unreal-editor-for-fortnite/01-fragment.verse

# Import the necessary modules for Verse and UI
using /Fortnite.com/Devices
using /Engine/Systems/GameplayTagManager
using /UnrealEngine.com/Temporary/Symbols

# Define our Verse Actor. This is the "Brain" of our operation.
actor CustomHealthUI is Activatable
    # This is the "Viewmodel". It's the bridge to the UI.
    # We bind it to a UMG Widget named "HealthWidget" in the editor.
    # Think of this as plugging the Battle Bus into the Drop Zone.
    var viewmodel: ViewModel = ViewModel {
        # The path to your UMG widget in the editor.
        # This must match the name of the widget asset in your Content Browser.
        widget_path: "/Game/Widgets/HealthWidget.HealthWidget_C"
    }

    # This is the "Storm Timer" - a variable that changes.
    # It holds the current health value (0 to 100).
    var current_health: float = 100.0

    # This function runs when the actor starts.
    on_begin() override:
        # Initialize the UI with full health
        update_health_ui()

    # This function is called when health changes.
    # In a real game, you'd call this from a Damage Event.
    # Here, we simulate it for the tutorial.
    function set_health(new_health: float):
        # Clamp the health between 0 and 100 (no negative health!)

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

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