Learn Unity Editor Scripting: Overview [Part 0]

Unity has become one of the leading Game Engines in the world. It helps developers create cross platform games very easily. One of the reasons Unity is such a great development environment for games is how flexible and powerful its Editor is.

Unity Editor comes with a lot of built in features. However the Editor programming API and developer features which let 3rd party developers (like you and me) extend it are the key to its success. Many developers have created additional assets and packages to add new features to Unity Editor. These meta features can be used by writing code for the Editor. Writing features for Unity Editor is commonly known as Editor Scripting.

For Editor Scripting you will need to know C# programming and basic knowledge of how Unity components work. If you are non programmer who uses Bolt, Play Maker or other visual scripting packages, you don’t need to extend the editor. The visual scripting packages are samples of what we are discussing here. They extend Unity Editor by providing you with visual scripting features!

There are various ways in which you can extend the editor. In this post, I’m going to give you an overview of all the methods. I’ll go into details on how to make changes with each one in the following articles in the series.

Companion Project

I am a strong believer in learning by doing. So I have created a companion github repository with a project that we complete in each post. You can get the code for the project in different states from the link below.

There are folders at the root of the repository named arena-0 to arena-6. In this series we add features to the same project in each post and keep building it up. Each folder is a standalone Unity project and corresponds to a post in this series.

For the next article, part1, which talks about Attributes, you should start with arena-0 and at the end of the article, if you make all changes as described, your project should look like arena-1.

For the second article, part2, which talks about Property Drawers, you should open arena-1 project in Unity and at the end of the article, it should look like arena-2.

And so forth!

Open arena-0 project in Unity. I’ve made the projects with 2019.4.11f but you should be able to migrate it to other versions.

The base project is very simple and has just a few scripts. Run the project. You can use the arrow keys to move around and your goal is to clear the arena of obstacles. When all obstacles are cleared or the player falls off the arena, the game ends and there is a message in the console indicating that.

Articles in this Series

With attributes, you hint the Editor code on how to treat and draw different components. attributes are the simplest way to extend the editor. It is also possible to create your own attributes and use them in your Property Drawers, Inspector Editors and Editor Windows!

You can define how fields of different Types are drawn in the Editor Inspector window. For example you can decide to show your own Color Picker in Editor instead of the default one. Or you could show different UI for float fields that represent angles vs speed vs time by adding attributes to them.

Custom Inspector Editors are very similar to Property Drawers. Instead of a common type, they handle drawing an entire Inspector section for a given component. They can be created only for types that extend MonoBehaviour or ScriptableObject.

You can create new menu items both in Unity Editor’s main menu and also in the context menus for each component.

You can create Editor Windows that can dock to Editor just like the inspector window or the console window. Common use cases for Editor Windows are showing custom UI for editing components, common settings for your package and an About window for your package.

You can show additional objects and gizmos similar to the move and scale handles or the collider editing boxes in the scene view.

Software Engineer | Indie Game Developer | Founder of No Such Studio. Follow me to learn how to make video games with Unity. http://www.nosuchstudio.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store