Using the BaseSpawner system

Overview

The base spawner system allows to dynamically spawn a base in the game world. The base can be placed in the map at design-time or loaded on-demand at runtime, and consists of building pieces and placeables. It can be removed/respawned as needed.

To use the system the steps are :

Creating a base asset

Building base in-game

As the base spawner uses regular building pieces, creating a base is done through the existing building system in game. This allows using building pieces and placeables so we can reuse existing features for health and stability. To do this we allow exporting a base from inside the game.

Creating the base is as simple as starting a new game and building the base where you want it to be in the world. Then using a cheat command ( ExportBase <BaseName> ) whilst looking at a part of the base.

This command will grab all buildings / placeables belonging to the master building you are looking at. You can grab more than 1 building at a time by using ExportBase <BaseName> <Radius> or ExportBaseMass <BaseName> . The Mass variant essentially tries to grab every building piece within replication range of any other building piece in the base.

Importing bases from the game to the editor

Bases exported in-game are turned into *.base files in the user’s Saved folder. These need to be imported into the editor before they can be used. This can be done by selecting the base file in the Editor to fill in a UBaseSaveData asset . This is done by creating a new Asset of type “Base Save Data” in /Content/SavedBases, then clicking the “…” on the “Source File Path” property and navigating to the .base file you wish to import. This can also be done on existing bases to overwrite their data, so caution should be used with this feature.

This functionality exists so that you don’t have to make bases in the editor, however if you do make bases in the editor, and export in the editor, instead of creating a .base file, it will create the .uasset file directly.

As a slight convenience feature, when the ExportBase command is run from Editor, the Editor will use a screenshot of the game’s viewport as the thumbnail of the base asset. This does not function when performed in-game or when .base files are re-imported into the Editor.

Spawning the base

Spawning the base is intended to be done automatically by placing a BP_BaseSpawner in a map/sub-level and setting its Base property to a UBaseSaveData of the desired base.

It can however, also be done manually by invoking the RespawnBase <BaseName> cheat. This cheat looks for a UAsset matching <BaseName> in /Content/SavedBases and spawns it and is mostly intended for quick tests in Editor.

Base Spawner

The loading of buildings in the game is wrapped inside an actor class (BaseSpawner), which will have functions exposed to control loading the base as well as keeping track of all the actors that belong to this base. We keep track of this so that it can also clean itself up completely if needed.

The Base Spawner has a few functions exposed:

When spawning a base we override the owner ID, as the one available at the time of saving is from the designer who built the base. The base is given a new Owner ID that should not match any existing player or group, and the player-facing owner name can be set via the m_OverrideBaseOwner string.

In addition to tracking the loading internally, the BaseSpawner will expose the event m_BaseSpawnedDelegate to blueprint, which executes when it finishes the spawn process. This event passes along every actor spawned by the Spawner so that additional setup or event bindings can be performed on the building pieces and placeables.

Base Spawners have a flag m_bRaidBase that, if set, will override the damageable settings on all spawned pieces to ignore server settings regarding PvP building damage or damage scaling to buildings. It also causes them to ignore in-world splines that attempt to block player building.

Viewing Buildings in editor

As you need to place NPCs and other trigger logic around the base for the PVE raid, we allow previewing the buildings in the editor. After you place the “BaseSpawner” actor on the level, and choose the asset you want it to use, it creates proxy meshes of the buildings and placeables in the editor world.

These meshes are then visible in the editor viewport and marked as “transient” so they’ll be cleaned up when the game starts and not saved to the actor / level.

If you turn off the m_bOptimizeProxyMesh flag, the proxy meshes will instead be individual actors, one per mesh, so that they can be manipulated and posed for screenshots.

Console Commands