Tutorial:Context Viewer (Warhammer 3)
The context viewer is a CA hack that can be activated in the settings menu in Total War: Warhammer 3.
You already knew that, of course, because you've been using it to cheat in your single player games.
But what you might not know is you can also use it to make UI mod creation easier. This guide is intended to teach you how to use the viewer and outline some places it can make the UI Modding workflow easier.
This guide is intended to provide examples of how to use this tool. Depending what you're using it for, you may want to first familiarize yourself with Component Context Objects.
Enabling the Context Viewer
To enable the context viewer, simply open the settings menu, hit the gear icon (fourth down on the left side menu), and then check the box under Modding.
You can now open the context viewer in game using your ` key. That's right above tab, to the left of 1, on a standard keyboard.
The context viewer appears in the centre of the screen by default but can be dragged around as you please.
Keep in mind: the context viewer won't always be stable. There are elements, context object types, and operations which will crash your game.
Using the Context Viewer
The Documentation folder in the game's data packfile has two documentation files: an HTML file which we will refer to as the Component Context Object documentation, or CCO Documentation, and a short microsoft word file called context_viewer_doc, which explains how to use the context viewer.
The image on the right shows the different key areas of the context viewer numbered 1 through 8. Here is a breakdown of these areas:
- You can press the context menu button to open the context menu on the left. This provides a handy list of shortcuts to get started with investigating the game state. These shortcuts are tailored to each game area. There is also a list of all exposed database contexts.
- You can press the Component tree button to open up the component tree view on the right hand side, this shows the whole UI hierarchy which is useful for inspecting and manipulating the game UI
- You can press the Events button to open up the events viewer on the right hand side (same space that the component tree occupies). While open you can see events appear in the list as they fire from the game.
- You can press the help button to easily access the documentation, which includes this document as well as the documentation for all the exposed context types
- The centre of the panel is where the information for the current inspect context is shown. Queries are shown first, followed by commands which are shown as buttons.
- This text input is where you can write out ‘context expressions’ to perform more advanced queries/commands. You will note some command buttons are disabled and have arguments next to their names. These can only be performed by using this text input since you can type out the command and pass any relevant parameters to the command to be performed. We often refer to this as the expression tester.
- You can press the back button to easily return to the previous inspected contexts
- You can press the refresh button to get the most up to date information for the current inspected context. Most information is updated live automatically, except for any queries returning other contexts or lists of contexts.
Furthermore, while the context viewer is open, you can middle mouse click on the following to inspect the context for that object immediately:
- UI objects
- Battle units
- Battle buildings
- Campaign characters
- Campaign settlements
You can additionally hold the ALT key while middle clicking components to select from a list of all components under the Mouse. This is useful for when multiple components overlap eachother.
Here are some common tasks the UI Context Viewer can help with.
Getting Faction Keys, Region Keys, and Other Information
For many common tasks, it is necessary to find faction, subtype or region keys. The context viewer can speed up this process.
To find the key of any region, select it in the UI, hover it's label (the 'zoom to settlement' button), and press the middle mouse button with the context viewer open. This will open the settlement UI in the context viewer. From here, you can expand the ContextsList field to see the available context, which will include the region context. The region key will be listed under ModelRegionContext on the region context page, and can be copied to the clipboard by right clicking the key.
To find the subtype and agent key of any character, select them in the UI, hover the first unit card, and press middle mouse with the context viewer open. This will open the unit card UI in the context viewer. From here, you can expand the ContextsList field to see the available context, which will include the character context. The subtype is listed under AgentSubtypeRecordContext, while the type is listed under AgentRecordContext.
In both region and character contexts, you can click links to go to other contexts. For instance, to find a faction key, you would open the context for a region or character that the faction owns and open the FactionContext.
Gathering UI Path/GUIDs for Scripting/XML Editing
When you are scripting using UI elements you often require the path from the root component to a given component you want to work with.
To use the context viewer to make this easier, use the component tree to navigate to the component that you are looking for.
CopyFullPathToClipboard() in the expression tester box. You can now paste this into your scripts.
You can also use the related
CopyStringToClipboard(GuidOriginal()) to copy the GUID - this can be used to find the component with the twui.xml files.