I want to present you one tool I’m using for my projects.
For now I’m not ready to share it because it’s kinda raw, but I want to understand would it be interesting and useful for you, and maybe get some feedback.
I’ve called it InstancedPlugin.
It’s created to extend editor functionality related to static meshes instancing, that can be used for optimization purposes, and more.
The system works with both C++ and Blueprints, and it is possible to create custom components and actors and override their functionality.
Plugin provides ability to convert static meshes to instances and vice-versa in editor.
Convertation process takes into account static mesh property and level property. So if you select different actors in different levels, converter will group them by levels and then by static meshes they are using, and converted actors will use static mesh property of their originals and will be placed in levels where their originals was.
Original actors will be deleted after convertation, and new actors will be selected. Any remained empty groups will be deleted.
New actors will be created with default properties, so if originals had some special settings for collision or so, you need to setup it again.
Converter section located on editor’s main toolbar and for now looks pretty budget:
But it works and here is a small example with Elven Ruins map.
This actor contains 71 instances of those big rocks and its converted in one click.
One more thing provided by this plugin, is ability to generate instances with desired algorithms.
Basically, instaces is just an array of transfroms, so it is possible to generate some transforms, change them, generate new transforms from previous ones, and so on.
This is done by creating and passing transforms between special operations components, which execute their functions in desired order.
There are few specializations of existing operations:
- to generate transforms by geometrical shapes, splines or random values;
- to change them by various randomizations or manually;
- to append, replace or remove transforms;
- to align locations with traces.
For example, you place special IPInstancedHISMActor in level. By default it contains only scene root and HierarchicalInstancedStaticMeshComponent (HISM).
You set static mesh property for HISM, and then add some operations, as childs of this HISM.
Then you need to adjust order of operations and their parameters.
In this example:
IPOperationTransformMultiply created to multiply transforms, but in this case its just creating first initial transfom.
IPOperationCircle3D generates 6 new transforms in circular shape.
IPOperationRandomTransform used to randomize previously created transforms.
IPOperationAlignByDirection will align them in specified direction.
IPOperationTransformRemove will remove one of them just because I want that.
This is just a little example. There are many variations of how it can be used.
The most interesting one is that you can generate transforms from other transforms, like circular placement inside rectangular shapes, randomized inside spheres.
Also, it is possible to use splines, but spline component must be a parent for instanced static mesh component, which will be parent for operations components.
Additionally, you may ask - is it possible to generate some procedural buildings with this system? Well, it depends.
If you need some simple buildings, like below, you can use Grid3D actor to generate it.
Just set section mesh, increase instances on Z axis and adjust it’s offset.
But if you want something really complex, it requires some really complex work.
And in the end in will look like actor with many instanced static mesh components and operations in it.
But in general it’s not a procedural generation, but more like semi-procedural construction.
Dynamic transformation during runtime
It is possible to update instances transforms during runtime. This is done by passing through array of instances transforms and change them by desired algorithm.
Just a small example - this actor checks distance between camera and every instance, and changing their transforms by specified delta transform.
Limitations & issues
It is possible to generate instances only in editor.
It’s funny, but I’m not even tried to generate instances during runtime. I think InstancedStaticMesh can do that, but I’m not sure about Hierarchical one. Anyway, with this system you can generate instances only in editor.
Instances are very limited. You can’t use them with destructibles or so.
Instances become inverted if use negative scale. I have not found a way to fix that. TwoSided materials not work.
For now, there is no Undo/Redo for converter operations.
It is required to set “Used with Instanced Static Meshes” flag in materials, better manually, because sometimes it’s not saved automatically.
As you can see there is no good UI for all of that. I’m just using default editor interface and interaction, and sometimes it’s weird.