Scripted Extensions in Unreal Engine 4.20
As usual, Unreal Engine 4.20 update brought tons of new features and tools.
One feature that could really come in handy is the ability to extend the Editor through Blueprints/Python scripting.
At this stage, this option comes in two flavors: Actor and Asset Editor extensions.
While Actor extensions will allow the user to create custom workflows for Actors that are already in the scene, the latter will allow for in-Editor Asset modifications, which is something super useful if you think about it.
Often times you find yourself wanting to automatically set some parameters on a bunch of Assets in the Content Browser; while this is something usually done through Property Matrix, there are quite a few cases where it is not enough and you need to access some deeper properties.
Let’s have a closer look.
Scripted Extensions via Blueprint scripting need to be done via Blutility. If you don’t know what it is, Blutility is just a special type of Blueprint that helps create custom Editor-callable functions and events.
In order to use Blutility, you need to enable it in the Editor Preferences:
[Optional] Some of the tools exposed for the Editor scripting will only appear if you enable the Editor Scripting Utilities in the Plugin section:
First we need to create a new Blutility asset:
When asked for the parent class, just select ActorActionUtility if you want to extend the Editor to handle Actors in the scene:
Once created, if you want to open it for editing, don’t just double-click on it: it would just open an empty window. Instead, right-click on it in the Content Browser and click on Edit Blueprint:
It appear just like a regular Blueprint editor window, except it does not have a Construction Script and a Viewport (of course).
The first and most important thing to do here is deciding on what kind of classes this action will work with. For example, let’s say we want to mass-edit only StaticMesh Actors in the scene.
We need to override a function called Get Supported Class and specify the class this action will work with:
This will allow the action to only show up if we are selecting one or more StaticMesh Actors in the scene; all other classes will be ignored.
Let’s say we create a function to add a new tag to all the selected StaticMesh Actors:
We want to make sure that the function (SetTag) has the Call In Editor option enabled, because that’s what will make a clickable button appear in the editor window:
Now if we select one or more StaticMesh Actors in the scene and right-click, a new contextual menu option appears, showing the name of our function (SetTag):
If we click on it, a new window will appear, asking for the new tag to add:
This happens because we added an Input pin to the function, so the Editor wants us to provide an input of that particular type.
If we don’t give the function any input pins, the function will be directly called, without showing any window with user-requested inputs.
Now let’s move on to an Asset Action example.
Say we imported a bunch of StaticMeshes and we want to mass-add a collision shape to them, but we don’t want to go through one by one.
Let’s create another Blutility asset, but this time we derive it from AssetActionUtility parent class.
We also need to override the GetSupportedClass function just like in the previous example, but this time we’ll pick StaticMesh:
Now we need to create a new function to do the dirty job. We’ll call it SetBoxCollision:
We used a GetSelectedAssets to get access to all the selected assets in the Content Browser.
The collision shape is added via the Add Simple Collision node (for this example, we used a Box shape).
Finally, we need to save the asset with the Save Loaded Asset node, which will make the changes permanent.
If we now select a few StaticMesh assets and right-click on them in the Content Browser, we’ll find our SetBoxCollision function:
This will add a simplified Box collision to all the StaticMesh assets and save them back.
Pretty nice, uh?