- Home /
How can I execute code in the editor?
Is there a way to execute code in the editor without adding a script with [ExecuteInEditor] to the scene?
I don't want to make a custom editor or property panel.
Did you look into the Editor classes? Like ScriptableWizard and such?
If you don't want a script to execute in edit mode, and you don't want a custom editor, what exactly do you want?
Answer by GameVortex · Jan 13, 2014 at 08:45 AM
So you do not want a script in the scene, and you do not want a custom editor panel/window. You basically just want some code to run in the background or run when you press a button?
There are some ways to do that.
To have a piece of code always running and checking for something you can use the **InitializeOnLoad** attribute and attach a function to the editor update event as described in the documentation.
The other way would be to make a static script with a static function and attach a menu option to that function.
Example:
public static CustomUtility
{
[MenuItem("MyCustomMenu/DoSomething")]
private static void DoSomething()
{
}
}
There will now be a new menu item at the top of the editor where you can select and run the DoSomething function.
Your answer
