Skip to content

Level loading & metadata help

Matt Filer edited this page Nov 14, 2020 · 1 revision

Levels are controlled by the level manager, which is a singleton and can be accessed anywhere in script using LevelManager.Instance.

Getting all level metadata info

To get metadata for all available levels, call LevelManager.Instance.LevelMetadata. This will return a list of LevelMetadata objects.

Each LevelMetadata object contains:

  • levelName - the level's name.
  • levelGUID - a unique identifying integer which should be used to link data to the level.
  • hasScreenshot - a bool defining if the level has a screenshot saved (should always be true, unless the map is old).
  • screenshotPath - the path to the level's screenshot, if hasScreenshot is true.
  • isLoaded - when called to load, this bool will be set true on completion.
  • isCampaignLevel - if this is a campaign map (a map developed in-house, and not UGC). Campaign maps have extra information to work out their sequence, as the campaign is expected to be played in the order configured in the toolkit.
  • isFirstCampaignLevel - if isCampaignLevel is true, this will be true for the first level in the campaign sequence. Only one level can ever have this value as true.
  • isLastCampaignLevel - if isCampaignLevel is true, this will be true for the last level in the campaign sequence. Only one level can ever have this value as true.
  • nextLevelGUID - if isCampaignLevel is true, this will be the GUID of the next level to load. Otherwise its value is -1.
  • hazardCount - the number of hazard props within the level.
  • goonCount - the maximum number of goons intended to be spawned in the level.
  • abilityCount - returns an AbilityCounts object which supplies the maximum number of ability uses intended for the level for Rally (blue), Medical (green), Fire (red), and Marshal (yellow).

Editing level metadata

To edit level metadata, use the DWB Toolkit tool in the root of the repo. Within the level manager in this toolkit you can set linked levels, level names, delete levels, and reorder levels.

As the tool writes and reads from a binary file, it's recommended that you ask around before editing anything, as you may overwrite someone else's changes in a merge.

This tool may also be helpful during development as a graphical way to find GUIDs for levels - however you should never hardcode GUIDs. The system is designed to be used in a dynamic way, allowing for maps to change and systems to not need to be rewritten.

Levels cannot be created in the toolkit, this must be done through the in-game level editor. All maps created in the level editor default to UGC, but this can be changed in the toolkit to suit the intended use of the map.

Loading a level

To load a level, pass the level's GUID to LevelManager.Instance.Load(level_guid). This will populate the level grid and metadata.

When a level has finished loading, the LevelManager.Instance.LevelLoadCompleted delegate is called. Subscribe to this delegate if you wish to execute code after a level has loaded (for example, assigning scripts to props). Similarly, the LevelManager.Instance.LevelUnloadCompleted delegate is called in the event of a level being unloaded.

Accessing metadata for current level

Once a level is requested to load, querying LevelManager.Instance.CurrentMeta will return you the LevelMetadata object for it.

Accessing the grid

Levels are created on top of a grid. To read more about the grid, click here. The grid can be accessed by calling LevelManager.Instance.Grid.

Clone this wiki locally