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 :
Create a base inside the game itself (as a regular player), using building pieces and placeables
Export the base to a UAsset using a cheat command (a .base file will be created if exported outside of the Editor)
Import the .base file into the editor (if it was created from a non-Editor build)
In editor, place a BaseSpawner actor in the world, and set the UBaseSaveData asset to use
This can be done directly in a level, or as part of a separate sub-level that is loaded on demand
Add any NPC spawns and/or static meshes alongside the base, using the preview mesh of the base to determine placement locations
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.
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 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.
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:
TrySpawnBase - under normal logic, a Base’s
m_bReadyToSpawn
flag must be set to “true” to be allowed to spawn. This can be set directly, or
m_bBeginReady
can be flagged as true to have it start in a ready state
DestroyBase
RebuildBase - calls DestroyBase(), then TrySpawnBase() after a configurable delay
SpawnBaseProxy - used in Editor to show a preview mesh of the chosen base; runs automatically whenever a new Base asset is chosen
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.
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.
ExportBase [BASENAME] [RADIUS] - Creates an asset named “[BASENAME]” that contains the data of the building you are currently looking at (within 1000m of you) and any placeables it is supporting. If you are in Editor, this will be in ‘Content/SavedBases’; if you are playing on Steam, it will be in your ‘Saved’ folder. The RADIUS parameter is optional, and will cause the base asset to contain not just the building being observed, but also any other buildings/placeables within Radius of it.
ExportBaseMass [BASENAME] [OVERRIDE_RADIUS] - Similar to ExportBase above, this cheat is used to export when the exact desired radius is unknown. This command will recursively find any buildings in the radius, so will grab any nearby buildings/placeables. The default radius is a Building’s Net Relevancy Distance, or the maximum range at which it can replicate to a client. The OVERRIDE_RADIUS parameter is optional and allows you to specify that you only want to grab building pieces/placeables within X units of each other, so you could grab a cluster of isolated buildings but not an entire base, if given the right value. That parameter is not expected to be used often.
RespawnBase [BASENAME] - If you have an asset named “[BASENAME]” in your /Content/SavedBases folder, attempts to reconstruct that base by spawning all associated building pieces and placeables in their same absolute world location on the current server.