sábado, 17 de junho de 2023

Creating tags in Verse

We can create tags in Verse to apply to some types of objects in UEFN. Tags are used to identify objects and we can use Verse code to search for all objects that have a specific tag.

In our game we are going to create a tag named coin_spawner and apply it to Item Spawners. At the start of the game we will get all the Item Spawners that have the tag to fill the CoinSpawnerDevices array with the references of the Item Spawners.

Creating a tag in Verse is very simple. You need to add the /Verse.org/Simulation/Tags module to the top of the Verse file and create a class with the name of the new tag using the tag class as the parent class. The definition of the tag class has to be done outside the collect_game_device class:

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

coin_spawner := class(tag){}

collect_game_device := class(creative_device):

    ...

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

To tag an object that is on the level, you need to add the Verse Tag Markup component to the object.

Select the Item Spawner that is on the level. In the Details tab, click the +Add button:


Search for tag and select Verse Tag Markup:


The Verse Tag Markup component will appear at the top of the Details tab. Select it to have its properties displayed at the bottom of the Details tab. Click the Edit... drop-down of the Tags property:


The Tags available in the project will be listed. Check the coin_spawner tag we created:


Save the UEFN project. The Item Spawner that is on the level has all the settings needed for our mini game. Make copies of the Item Spawner we configured and place the copies in the grid cells around the Player Spawner for a total of 8 Item Spawners: 


A quick way to duplicate objects in the Viewport is to hold the Alt key and drag one of the selected object's axis arrows.

The copies of the Item Spawner already have the gold coin and the coin_spawner tag.

In the next article we will see how to find the objects that have a tag and how to fill an array with the references of these objects.


Table of Contents Verse