Editor Events
Editor Events are events that are broadcast globally throughout the editor and can be listened to/fired from any Editor Project. These are useful for creating your own custom Editor Tools and making sure they can work in tandem with existing systems.
Hooking into an EditorEvent
Hooking into an Editor Event allows you to run additional code whenever an event is called. You can control the order at which event hooks are triggered via the Priority
variable. Events with a lower Priority run first.
// Hooking into a named event
[Event( "scene.stop", Priority = 100 )]
void OnSceneStop()
{
Log.Info( "The scene has stopped" );
}
// Shorthands for frequently used events
[EditorEvent.Hotload]
void OnHotload()
{
Log.Info( "You've hotloaded!" );
}
Just make sure that you have the same arguments that the EditorEvent is looking for. See the table below.
Calling a Custom EditorEvent
// Calling an event with 0-3 arguments
EditorEvent.Run( "customevent.test" ); // No arguments
EditorEvent.Run( "customevent.add", 1, 2); // 2 arguments
// Calling an event via an interface (theoretically unlimited arguments)
// This will run the event on any Editor Widget that implements the custom interface
EditorEvent.RunInterface<ICustomEvent>( x => x.MyCustomEvent(1,2,3,4,5) );
Event Interfaces
While string-based events still exist, we prefer to use event interfaces nowadays. We find that they’re more stable than strings. It’s more obvious if things are using it, and it’s really IntelliSense friendly.
To use the interface, you just implement it. They’re coded in a way that means you don’t have to implement each member, so you can just implement what you want to listen to.
public class MyCustomWidget : Widget, ResourceLibrary.IEventListener
{
void ResourceLibrary.IEventListener.OnRegister( GameResource resource )
{
Log.Info( $"{resource} has been registered!" );
}
}
AssetSystem.IEventListener
/// <summary>
/// An asset has been modified
/// </summary>
void OnAssetChanged( Asset asset ) { }
/// <summary>
/// The thumbnail for an asset has been updated
/// </summary>
void OnAssetThumbGenerated( Asset asset ) { }
/// <summary>
/// Changes have been detected in the asset system. We won't tell you what, but
/// you probably need to update the asset list or something.
/// </summary>
void OnAssetSystemChanges() { }
/// <summary>
/// Called when a new tag has been added to the asset system.
/// </summary>
void OnAssetTagsChanged() { }
ResourceLibrary.IEventListener
/// <summary>
/// Called when a new resource has been registered
/// </summary>
void OnRegister( GameResource resource ) { }
/// <summary>
/// Called when a previously known resource has been unregistered
/// </summary>
void OnUnregister( GameResource resource ) { }
/// <summary>
/// Called when the source file of a known resource has been externally modified on disk
/// </summary>
void OnExternalChanges( GameResource resource ) { }
/// <summary>
/// Called when the source file of a known resource has been externally modified on disk
/// and after it has been fully loaded (after post load is called)
/// </summary>
void OnExternalChangesPostLoad( GameResource resource ) { }
Other Default EditorEvents
Editor
Event | Arguments | Invokes |
---|---|---|
| EditorMainWindow | When the editor has just started |
| Every frame | |
| When a hotload occurs | |
| When assemblies are changed | |
| When assemblies are changed. Runs after | |
| When the editor is shutting down | |
| When Project Settings are updated | |
| When Editor Keybinds have been changed |
Asset System
Event | Arguments | Invokes |
---|---|---|
| When a new folder was created | |
| AssetPickerParameters | When opening an Asset Picker |
| string | When you click “Show in Asset Browser” |
| AssetContextMenu | When an asset is right clicked |
| FolderContextMenu | When a folder is right clicked |
| string | When a file has changed in the “Content” path |
| string | When a shader starts compiling |
| string | When opening a shader |
| Package | When you update a package |
| Package | When a package is installed |
| Package | When a package is uninstalled |
| Package | When you favourite a package |
| Package | When you upvote/downvote |
Scenes
Event | Arguments | Invokes |
---|---|---|
| When a Scene or Prefab is opened | |
| When you click the Play button | |
| When the Scene enters Play Mode | |
| When the Scene exits Play Mode | |
| Every second a Scene is open | |
| Scene | When a Scene is saved |
Widgets
Event | Arguments | Invokes |
---|---|---|
| When highlighting a Panel in the “UI Panels” tab | |
| When the Editor receives a mouse event | |
| StatusBar | When the status bar is being built |
| HeadBarEvent | When the header bar is build built |
| NavigationView | When the preferences widget is opened |
Tools
Event | Arguments | Invokes |
---|---|---|
| Menu | When launching ModelDoc |
| When hammer is opened | |
| When hammer selection has changed | |
| MapView | For each MapView before rendering begins |
| When the hammer hud is rendered | |
| Menu, MapView | When the MapView is right clicked |
| ActionGraph, GameResource | Right before an ActionGraph is saved |
| ActionGraph | When an ActionGraph is saved |
| IMessageContext | When inspecting anything in the ActionGraph |
| FindReflectionNodeTypesEvent | When attempting to get a list of reflection nodes |
| FindGraphTargetEvent | When attempting to find the target |
| GetGlobalNodeTypesEvent | When attempting to get global nodes |
| GetLocalNodeTypesEvent | When attempting to get local nodes |
| QueryNodeTypesEvent | When filtering through an existing list of nodes |
| PopulateNodeMenuEvent | When populating the node menu |
| PopulateCreateSubGraphMenuEvent | When right clicking to create a sub-graph |
| PopulateOutputPlugMenuEvent | When clicking and dragging out of an output plug |
| PopulateInputPlugMenuEvent | When clicking and dragging out of an input plug |
| GoToPlugSourceEvent | When double clicking on a plug to go to it’s source |
| BuildInputLabelEvent | When building an input label |
| GetEditorPropertiesEvent | Called when launching ActionGraph |