s&box docs

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.

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!" );
	}
}

For widgets event listeners will register automatically, if you want to listen to events on a non widget class you will manually need to call EditorEvent.Register( myCustomListenerInstance );

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

EventArgumentsInvokes
editor.createdEditorMainWindowWhen the editor has just started
tool.frameEvery frame
hotloadedWhen a hotload occurs
refreshWhen assemblies are changed
tools.gamedata.refreshWhen assemblies are changed. Runs after refresh
app.exitWhen the editor is shutting down
localaddons.changedWhen Project Settings are updated
keybinds.updateWhen Editor Keybinds have been changed

Asset System

EventArgumentsInvokes
assetsystem.newfolderWhen a new folder was created
assetsystem.openpickerAssetPickerParametersWhen opening an Asset Picker
assetsystem.highlightstringWhen you click "Show in Asset Browser"
asset.contextmenuAssetContextMenuWhen an asset is right clicked
asset.nativecontextmenuFolderContextMenuWhen a folder is right clicked
content.changedstringWhen a file has changed in the "Content" path
compile.shaderstringWhen a shader starts compiling
open.shaderstringWhen opening a shader
package.changedPackageWhen you update a package
package.changed.installedPackageWhen a package is installed
package.changed.uninstalledPackageWhen a package is uninstalled
package.changed.favouritePackageWhen you favourite a package
package.changed.ratingPackageWhen you upvote/downvote

Scenes

EventArgumentsInvokes
scene.openWhen a Scene or Prefab is opened
scene.startplayWhen you click the Play button
scene.playWhen the Scene enters Play Mode
scene.stopWhen the Scene exits Play Mode
scene.session.saveEvery second a Scene is open
scene.savedSceneWhen a Scene is saved

Widgets

EventArgumentsInvokes
paintoverlayWhen highlighting a Panel in the "UI Panels" tab
qt.mousepressedWhen the Editor receives a mouse event
gameframe.statusbarStatusBarWhen the status bar is being built(Used to add your own Widgets)
tools.headerbar.buildHeadBarEventWhen the header bar is build built(Used to add your own Widgets)
editor.preferencesNavigationViewWhen the preferences widget is opened(Used to add your own pages)

Tools

EventArgumentsInvokes
modeldoc.menu.toolsMenuWhen launching ModelDoc
hammer.initializedWhen hammer is opened
hammer.selection.changedWhen hammer selection has changed
hammer.rendermapviewMapViewFor each MapView before rendering begins
hammer.rendermapviewhudWhen the hammer hud is rendered
hammer.mapview.contextmenuMenu, MapViewWhen the MapView is right clicked
actiongraph.savingActionGraph, GameResourceRight before an ActionGraph is saved
actiongraph.savedActionGraphWhen an ActionGraph is saved
actiongraph.inspectIMessageContextWhen inspecting anything in the ActionGraph
actiongraph.findreflectionnodesFindReflectionNodeTypesEventWhen attempting to get a list of reflection nodes
actiongraph.findtargetFindGraphTargetEventWhen attempting to find the target
actiongraph.globalnodesGetGlobalNodeTypesEventWhen attempting to get global nodes
actiongraph.localnodesGetLocalNodeTypesEventWhen attempting to get local nodes
actiongraph.querynodesQueryNodeTypesEventWhen filtering through an existing list of nodes
actiongraph.nodemenuPopulateNodeMenuEventWhen populating the node menu
actiongraph.createsubgraphmenuPopulateCreateSubGraphMenuEventWhen right clicking to create a sub-graph
actiongraph.outputplugmenuPopulateOutputPlugMenuEventWhen clicking and dragging out of an output plug
actiongraph.inputplugmenuPopulateInputPlugMenuEventWhen clicking and dragging out of an input plug
actiongraph.gotoplugsourceGoToPlugSourceEventWhen double clicking on a plug to go to it's source
actiongraph.inputlabelBuildInputLabelEventWhen building an input label
actiongraph.geteditorpropertiesGetEditorPropertiesEventCalled when launching ActionGraph

Referenced API

Canonical API pages mentioned in this guide.

Created at:
Updated at:

On this page