domingo, 29 de março de 2026

UEFN Verse: Logging and Log channel

Log messages can help identify issues in your Verse code. These messages can be viewed in the in-game log tab and in the UEFN Output Log window. 

Logging in Verse requires two classes: log and log_channel.

The log_channel is used only to identify the source of the message. Its name is added to the beginning of the message. 

You need to create a subclass of log_channel at the module scope, that is, outside of classes or functions. The code below shows an example of a log_channel

log_general := class(log_channel){}

The next step is to create an instance of the log class inside a class or function, specifying the log_channel to be used:

LoggerGeneral:log = log{Channel:=log_general}

There are five log levels used to categorize messages: Debug, Verbose, Normal, Warning and Error.

Logs with Debug and Verbose levels appear only in the in-game log tab. They do not appear in the UEFN Output Log.

Logs with Warning and Error levels are displayed in different colors to draw attention.

A default log level can be defined when the log is created: 

LoggerGeneral:log = log{Channel:=log_general, DefaultLevel:=log_level.Warning}

To write to the log, use the Print function of the log class:

LoggerGeneral.Print("Experience started")

You can pass the log level as a parameter:

LoggerGeneral.Print("Data not found", ?Level := log_level.Error)

Another useful piece of information for debugging is the Call Stack, which shows the sequence of function calls leading to the current point in the code. Use the PrintCallStack function from the log class to log the Call Stack. 

LoggerGeneral.PrintCallStack()

To illustrate the use of logging, we will create a device that uses two logs. One will be used for general system messages, and the other for logging messages when buttons are pressed by the player. Different log levels will be used.

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

In Device Name put log_example_device and click the Create Empty button.

Copy the Verse code below into the log_example_device file:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

log_general := class(log_channel){}
log_buttons := class(log_channel){}

log_example_device := class(creative_device):

    LoggerGeneral:log = log{Channel:=log_general}
    LoggerButtons:log = log{Channel:=log_buttons, 
                            DefaultLevel := log_level.Warning}

    var BtnWarningCount: int = 0
    var BtnErrorCount: int = 0

    @editable
    ButtonWarning : button_device = button_device{}

    @editable
    ButtonError : button_device = button_device{}

    OnBegin<override>()<suspends>:void=
        ButtonWarning.InteractedWithEvent.Subscribe(ButtonWarningPressed)
        ButtonError.InteractedWithEvent.Subscribe(ButtonErrorPressed)
        LoggerGeneral.Print("Experience started.")

    ButtonWarningPressed(Agent:agent):void=
        set BtnWarningCount += 1
        LoggerButtons.Print("ButtonWarning was pressed {BtnWarningCount} times")

    ButtonErrorPressed(Agent:agent):void=
        set BtnErrorCount += 1
        LoggerButtons.Print("ButtonError was pressed {BtnErrorCount} times", 
                            ?Level := log_level.Error)
        LoggerButtons.PrintCallStack()

The log_example_device contains two button_device instances that are used to log messages when pressed. One button is used for Warning level messages, and the other for Error level messages.

The OnBegin function subscribes the functions to be called on the buttons when they are pressed, and then logs a message using LoggerGeneral.

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

Access the Content Drawer and add the log_example_device to the level. Then add two Button Devices to the level. 



Select the log_example_device at the level. In the Details tab, Select the references to the buttons in the level. 


Save the level and click the Launch Session button to load the level in Fortnite. Press the buttons a few times. Then switch to UEFN and check the messages logged in the Output Log.