Entities & Components: Bolting Powers Onto Things in Verse
Tutorial beginner

Entities & Components: Bolting Powers Onto Things in Verse

Updated beginner Scene Graph

Entities & Components: Bolting Powers Onto Things in Verse

In Part 1 we learned the two big nouns: an entity is a thing in the world, and a component is a power you bolt onto it. Now let's write the real Verse. We'll do three things, in order:

  1. Write your own component (the most common thing you'll actually do).
  2. Read a component that's already on an entity.
  3. Add a component to an entity from code.

Keep The Grammar of Verse in the back of your mind — every line is still a sentence.

The most useful skill: writing your own component

<!-- section-art:the-most-useful-skill-writing-your-own-component --> Entities & Components: Bolting Powers Onto Things in Verse: The most useful skill: writing your own component

Bolt-On Component

Most of your Scene Graph code won't create entities from scratch. It will add behavior to entities you've already placed in the editor — by writing a custom component and bolting it on. So this is the first thing to learn.

In UEFN you make one by choosing Add Component > New Verse Component, then the Scene Graph Component template. That gives you a file. Here's what a real, complete one looks like — this is straight from Epic's own "make a platform disappear on a loop" example:

using { /Verse.org }
using { /Verse.org/Native }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }

# A Verse-authored component you can add to entities.
# It makes the entity appear and disappear on a loop.
disappear_on_loop_component := class<final_super>(component):

    # How long, in seconds, the entity stays hidden. @editable means
    # you can tweak this number in the editor without touching code.
    @editable
    var Duration<public>:float = 2.0

    # Runs when this component starts simulating in a running game.
    OnBeginSimulation<override>():void =
        spawn:
            RunLoop()

    RunLoop()<suspends>:void =
        loop:
            Sleep(Duration)
            GetEntity[].Hide()
            Sleep(Duration)
            GetEntity[].Show()```

Let's read it like sentences, top to bottom:

- **`disappear_on_loop_component := class<final_super>(component):`** — *"I'm defining a new kind of component called `disappear_on_loop_component`."* The part in the parentheses, `(component)`, means *"it's a kind of `component`"* — it inherits the base power. The label **`<final_super>`** is a required tag any time you make a component you intend to bolt onto an entity; it just promises the class sits directly on top of `component`. You'll write it every time, like a magic word.
- **`@editable var Duration<public>:float = 2.0`**  a setting. `var` means it can change; `:float` means it's a decimal number; `= 2.0` is its starting value. **`@editable`** is the gift: it makes `Duration` show up as a knob in the editor's Details panel, so a designer can change it without code.
- **`OnSimulate<override>()<suspends>:void =`**  a **lifetime method**. The Scene Graph calls this automatically once the component is up and running in the game. `<override>` says *"I'm replacing the empty default version."* `<suspends>` says *"this verb is allowed to pause and wait"* (remember effects from the grammar series). `:void` means it hands nothing back.
- **`loop:` ... `Sleep(Duration)`**  wait that many seconds. `Sleep` is a real Verse function for pausing.
- **`Entity.Hide()` / `Entity.Show()`**  here `Entity` is a built-in word every component has: it's *the entity this component is bolted onto*. (`Hide` and `Show` in this example are little helper verbs Epic defines just below, which flip the mesh on and off — we'll see how next.)

That one component, dropped onto any entity with a shape, makes it blink in and out forever. No entities created, no tree-walking  just *behavior bolted onto a thing.*

## Lifetime methods: the four moments the Scene Graph calls you

You saw `OnSimulate`. It's one of a small family of **lifetime methods** — moments in a component's life when the Scene Graph automatically runs your code. The main ones, in order:

- **`OnAddedToScene`**  the component just got added to the live scene. Good for early setup; after this, you're allowed to look around for other components.
- **`OnBeginSimulation`** — the component is about to start running. Good for instant, must-finish-now setup.
- **`OnSimulate`** — your main running logic. It's `<suspends>`, so this is where loops, waits, and ongoing behavior live.
- **`OnEndSimulation`**  things are shutting down; clean up here.

You only override the ones you need. Want something to happen once at startup? Override `OnBeginSimulation`. Want an ongoing loop? Override `OnSimulate`. (If you override `OnBeginSimulation`, it's polite to call the parent's version first with `(super:)OnBeginSimulation()`, which Epic's examples do.)

## Reading a component that's already there: `GetComponent`

Often your entity *already has* a power you want to poke at  a mesh, a light  and you just need a handle on it. That's **`GetComponent`**. Here are the `Hide`/`Show` helpers from that same Epic example, which show the pattern:

```verse
# Hide the entity by turning off its mesh.
(Entity:entity).Hide():void =
    if:
        Mesh := Entity.GetComponent[mesh_component]
    then:
        Mesh.Disable()

# Show the entity by turning its mesh back on.
(Entity:entity).Show():void =
    if:
        Mesh := Entity.GetComponent[mesh_component]
    then:
        Mesh.Enable()
verse
# Inside a component, give this entity a particle effect at startup.
# BlowingParticles is a Niagara effect exposed in Assets.digest.verse.
OnBeginSimulation<override>():void =
    (super:)OnBeginSimulation()
    VFX:particle_system_component = BlowingParticles:
        Entity := Entity
        AutoPlay := true
    Entity.AddComponents(array{VFX})

Read it: "make a new particle_system_component (named VFX) belonging to this Entity, set it to auto-play, then add it to the entity's list of components." Note Entity := Entity — every component must be told which entity it belongs to when you build it, because (per the docs) "components cannot be moved between parents." A component is born attached to exactly one entity for life.

The matching verb for entities is AddEntities (add child things, not powers) — that's a Part 3 topic, since it's really about the family tree.

The mental model, sharpened

<!-- section-art:the-mental-model-sharpened --> Entities & Components: Bolting Powers Onto Things in Verse: The mental model, sharpened

Component Attachment

Put the three verbs side by side and the system reads cleanly:

  • Define a powerclass<final_super>(component): with On... lifetime methods.
  • Read a power that's thereEntity.GetComponent[some_component] (might fail, so guard with if:).
  • Add a powerEntity.AddComponents(array{...}).

Everything else in the Scene Graph is variations on these. Lights, meshes, sounds, interactions — they're all just components you get, enable, disable, or add.

Why this helps you boss around an AI

You can now give precise instructions: "Write a class<final_super>(component) with an @editable var Speed:float, override OnSimulate<suspends>, and inside it GetComponent[mesh_component] and move it." That sentence is buildable as-is. The vague version — "make the thing move" — isn't. The more real component words you know, the sharper the work you can direct.

Quick recap

  • Make your own power with class<final_super>(component): and override lifetime methods (OnBeginSimulation, OnSimulate, ...).
  • @editable turns a var into an editor knob; var ... :float = 2.0 is the grammar from Part 1 of the grammar series.
  • GetComponent[...] reads a power that's already on an entity — square brackets because it can fail, so guard it with if:.
  • Components have Enable() / Disable() to flip them on and off without deleting anything.
  • AddComponents(array{...}) bolts new powers on; a component is born attached to one Entity and stays there.

Next: Hierarchy & Transforms — how things hang off each other in the tree, and how position actually works.

References

Get the complete code — free

You've read the full walkthrough. The complete, copy-paste-ready Verse solution is free for members — sign in to unlock it.

Free with your BrainDead.TV / BrainDeadGuild Discord account. The walkthrough above is always free.

Verse source files

Check your understanding

Test yourself with an interactive quiz and track your progress + earn XP — free for members.

Turn this into a guided course

Add Verse Scene Graph — creating entities, adding and reading components to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.

Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.

Comments

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