sexta-feira, 5 de dezembro de 2025

UEFN Verse SG: Creating a Scene Graph component

In this article, we will create a simple Scene Graph component that will help us understand the relationship between entity, component, and Prefab.

Our component will generate a sort of platform bridge. It will have two fields that will be used to define the number of platforms generated and the distance between them.

The image below shows the platform bridge that will be generated:


We'll use UEFN's modeling mode to create a mesh that will serve as the platform. Change the editor to Modeling mode:


In the modeling panel, select the Cylinder shape:


Change the Cylinder Height to 50 and select a material. I chose the MI_Japanese_Wooden_Floor material.


Click on the level to position the mesh, and then click the Accept button to create the mesh.



In the Content Drawer, you'll see that a folder called Meshes has been created inside your project folder. Access the folder, select the mesh, and press F2 to rename it. Rename the Static Mesh to Platform_cylinder. Double-click the mesh to open the static mesh editor.

We need to add collision to the mesh. Let's use a simple shape. In the Collision menu, choose the Add Box Simplified Collision option. Save and close the editor.


It is necessary to compile the Verse code in order to create the mesh component in Verse that represents the mesh we created. To compile, go to the menu Verse > Compile Verse Code.


Now let's create the Prefab that will represent a platform. Access the Content Drawer, select your project folder, and right-click on an empty space to open the menu. Select Entity Prefab Definition and name this as Prefab_platform.



Double-click the Prefab_platform that was created to open the Prefab editor. In the Details tab, click the +Component button and select the transform_component. This component is necessary to define the position, rotation, and scale of the entity at the level.


Add another component and select the mesh_component. The mesh components available in the project will be displayed. Select the Platform_cylinder that we created.


The image below from the Prefab editor shows what the Prefab_platform looks like.



Save the Prefab and close the Prefab editor.

When we create a Prefab, UEFN creates a Verse class from this Prefab and registers it in the Assets.digest.verse file. This allows the creation of Prefab instances directly in the Verse code.

The next step is to create the Scene Graph component, which will generate multiple instances of Prefab_platform in different positions and add them to the entity that owns the component.

Open Verse Explorer, right-click on the project name, and select the option Add new Verse file to project.

Choose the Scene Graph Component template and name it platform_row_component. Click the Create Empty button.


Double-click the platform_row_component file to open it in Visual Studio Code.

Copy the Verse code below into the platform_row_component file:

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

platform_row_component<public> := class<final_super>(component):

    @editable
    NumberOfPlatforms<public>:int = 10

    @editable
    PlatformDistance<public>:float = 300.0

    OnBeginSimulation<override>():void =
        # Run OnBeginSimulation from the parent class
        (super:)OnBeginSimulation()

        for (Index := 0..NumberOfPlatforms - 1):
            Position := vector3{Forward := PlatformDistance * Index}

            NewPlatform := Prefab_platform{}

            NewPlatform.SetLocalTransform( transform{Translation := Position} )
            
            Entity.AddEntities( array{NewPlatform} )        
             
    OnSimulate<override>()<suspends>:void =
        Print("OnSimulate")


Let's analyze this code piece by piece. The line below declares that platform_row_component is a class that inherits from the component class. In other words, component is the parent class and is also known as the superclass.

platform_row_component<public> := class<final_super>(component): 

The <public> specifier indicates that the class will be available everywhere. The <final_super> specifier is a requirement of the Scene Graph to ensure the integrity of the system of entities and components.

Our component has two fields that can be edited directly in UEFN to configure the generation of the platform bridge.
    @editable
    NumberOfPlatforms<public>:int = 10

    @editable
    PlatformDistance<public>:float = 300.0

These fields use the <public> specifier to make them visible to other components. In Scene Graph programming, interaction between components is very common, so using constants with <public> access facilitates access to this data without the risk of it being modified by other components.

The Scene Graph component template code provides two functions where you can place the code that will be executed when the simulation starts:
  •  OnBeginSimulation<override>( ) : This function executes and completes immediately. Ideal for component preparation code that will only be executed once.
  •  OnSimulate<override>()<suspends> The <suspends> specifier indicates that this is an asynchronous function, meaning its completion does not need to be immediate. For example, here you can place code that makes the component wait for player interaction.

The code for generating the platform bridge is in the OnBeginSimulation<override> function. Right at the beginning of this function, we have the following line of code:
    (super:)OnBeginSimulation()

The component class, which is used as a superclass for the components, has an OnBeginSimulation() function that requires some configuration code to be executed. The (super:) indicates that the OnBeginSimulation() function to be executed is from the superclass.

The for expression is used to repeat its code block for each platform that will be generated. The value of Index is modified for each iteration of the for loop. The first value is 0 and the last value will be NumberOfPlatforms - 1.
    for (Index := 0..NumberOfPlatforms - 1): 

Inside the for loop, the Index value is used to calculate the position where the new Prefab_platform instance will be created.

Position := vector3{Forward := PlatformDistance * Index} 

This position is relative to the position of the entity that will contain our component. The platforms will be created following the Forward axis. To change the direction in which the platform bridge will be created, simply rotate the entity at the level.

Note: Since version 36.00, UEFN has used the LUF coordinate system. In this system, the coordinate axes are Left, Up, and Forward. To learn more about LUF, please refer to this Epic Games documentation: 

Left-Up-Forward Coordinate System


The constant NewPlatform stores a new instance of our Prefab_platform:

NewPlatform := Prefab_platform{} 


The SetLocalTransform() function specifies the platform relative transformation. In our example, you only need to set the Translation field of the transform. Rotation and scale use the default values.

NewPlatform.SetLocalTransform( transform{Translation := Position} ) 


The new instance of Prefab_platform needs to be added to the entity that contains our component. The component class has the constant Entity, which is a reference to this entity. The AddEntities function adds an array of entities to an entity. Therefore, it was necessary to create an array containing the instance referenced by NewPlatform.

Entity.AddEntities( array{NewPlatform} )


These actions are repeated for each iteration of the for loop.

Save the file and compile the Verse code using the Verse > Compile Verse Code option from the UEFN menu.

To complete this example, we need to add an entity at the level and add our platform_row_component to this entity. Follow these steps:

1. In UEFN, access the Place Actors panel. If the panel is not visible, access it in the top Window menu.

2. In Place Actors, select the Entities category and drag an entity to the level. In the Outliner tab, rename this new entity to PlatformBridge for easier identification.

3.  In the Details tab, click the +Component button and select our platform_row_component.


4. In the Details tab, you can modify the values ​​that are used in generating the platform bridge.


5. Position the entity slightly above the floor level to prevent the platform bridge from being created on the floor.


Save the level and load it in Fortnite by clicking the Launch Session button to see the platform bridge generated by our component.


Note: Unfortunately, the collision of platforms generated by the Verse code is not working correctly. My idea with this example was for the player to jump on the platforms to get across a chasm. However, the player is unable to stand on the platform.

The created Prefab is correct. If we add an instance of the Prefab directly to the level using UEFN, the collision works correctly and the player can stand on the platform.

I researched this situation online and confirmed that the Verse code is correct. I found the following item on an Epic Games page about Scene Graph issues:




This is the problem that must be occurring with our example. Scene Graph is still in Beta and they should fix this problem soon.
(December 2025) 


Table of Contents Verse