Verse Wiki — the Verse handbook for Blueprint authors
Deep Dive · EXTRA

Hand-Rolling ToString for enum: The case Mapping Pattern

Lesson 11 warned you: an enum can't be pushed to the screen with Print String, nor spliced into the line of text you want to show. This page presents the standard fix the community has settled on — a single case mapping function; name it ToString and a hidden perk comes free.

1. The Problem: enum Is Mute

You've almost certainly done this while debugging: which step has the state machine reached? Drop a log (Print String) and look. So you dash off Print("Current state: {Current}") — and Compile throws cold water on it immediately: enums carry no built-in textual form; they can't be pushed out with Print String and can't be spliced into the line you want to show. Nor can they turn into integers (there's simply no number behind an entry) — the well-trafficked forum thread «Casting enum to string and int» confirms this is deliberate language design, not an omission.

Why deliberate? Because an enum member's identity is «itself»: zombie_state.Walk is not 1, and it's not "Walk" either — it's just one of three nameplates. When it comes to giving it human-readable text, Verse's stance is: you decide; the language won't guess for you.

2. The Standard Fix: A case Mapping Function

The fix is reassuringly plain: write a function that uses case to map each member to a string. It's the grown-up version of that PhaseLabel from the end of Lesson 11:

zombie_debug_device.verse
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }

zombie_state := enum{Idle, Walk, Attack}

# Name it ToString: string interpolation finds it automatically (see below)
ToString(State:zombie_state)<computes>:string =
    case (State):
        zombie_state.Idle => "Idle"
        zombie_state.Walk => "Walk"
        zombie_state.Attack => "Attack"

zombie_debug_device := class(creative_device):

    OnBegin<override>()<suspends>:void =
        Current := zombie_state.Walk
        Print("Zombie state: {Current}")

▸ Blueprint translation: first create a zombie_state enumeration asset (Idle / Walk / Attack). ToString is a Blueprint function that takes one entry and routes it through the case splitter: Idle yields "Idle", Walk yields "Walk", Attack yields "Attack" — a piece of text apiece. Finally, in the device's game start (Event BeginPlay), the current state goes out through Print String — and notice that the interpolation {Current} somehow understands this enum now. The secret drops in the next section.

A few details deserve a pause. First, case spells out all three entries with no fallback exit (the Default pin on Blueprint's Switch on Enum) — allowed for a default closed enum, and in fact better: add zombie_state.Run later and forget this function, and Compile names exactly whom you missed; the safety net comes free. Second, that <computes> hanging on the function header is a «specifier» meaning «this function does pure computation only and touches nothing in the outside world» — that's how the original forum post writes it; the full story of specifiers unfolds in a later chapter, so for now copy it verbatim.

3. The Hidden Perk: Interpolation Adopts ToString Automatically

Look at the last line of the example above: Print("Zombie state: {Current}") — an enum stuffed straight between the braces, and Compile let it pass? That's the hidden perk of naming the function ToString: a {X} inside a piece of text actually goes looking for a currently visible ToString function that can turn X into text, and puts it to work. Numbers (int, float) can go straight into {} because the engine ships a ToString for them; give zombie_state a same-named one and your enum can be spliced into text and printed too — logging code so clean the type might as well have been born talking.

Two side facts while we're here. The original poster also wished for a form like enum{Missing = "missing"} — hanging a piece of text on each entry while building the enum — which doesn't exist yet; file it under «this language is still evolving». Also, the official community tutorial «Understanding, Accessing, and Making an Enum» covers more practical enum usage — for instance, flip Instance Editable on an enum variable (@editable, that little eye on the variable) and it becomes a dropdown in the level's Details panel, letting designers switch states without touching code — enum's type safety stretching all the way into the editor UI.

What extra benefit comes from naming the enum's mapping function ToString (rather than, say, GetLabel)?

Sources

Compiled from the Epic developer forums and the official community tutorials: Casting enum to string and int — Epic Developer Forums ↗ · Understanding, Accessing, and Making an Enum in Verse Code — Epic official community tutorial ↗