# 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!) current_health = max(0.0, min(100.0, new_health)) # Send the update to the UI update_health_ui() # This function talks to the Viewmodel. # It’s like sending a message from the Bus to the Player. function update_health_ui(): # Calculate the percentage (0.0 to 1.0) health_percentage = current_health / 100.0 # Use the Viewmodel to set the "Value" parameter of the Progress Bar. # "HealthBar" is the name of the Progress Bar in your UMG widget. viewmodel.set_float("HealthBar.Value", health_percentage) # Optional: Change color based on health # If health is low, turn the bar red. If high, turn it green. if current_health < 30.0: viewmodel.set_color("HealthBar.BackgroundColor", {R: 1.0, G: 0.0, B: 0.0, A: 1.0}) # Red else: viewmodel.set_color("HealthBar.BackgroundColor", {R: 0.0, G: 1.0, B: 0.0, A: 1.0}) # Green # Event: When the actor is activated (e.g., by a button press for testing) on_activate(): # Simulate taking damage set_health(current_health - 25.0)