Last year I wanted to learn how to procedurally generate meshes in Unreal, so I put together a few quick tests of my own. This got some interest from people here so I decided to clean it up and release it for free!
I really hope this will be useful to others who also want to play with geometry generation in Unreal.
The purpose of this project is to provide examples on how to generate geometry in code, from simple cubes to more complex geometry generated from fractal algorithms.
I would love for this to become a community project, so I will accept pull requests for new samples as well as any corrections to my code. I’m also willing to add contributors directly if anyone is interested!
Please note that I wrote the code to be readable, trying my best to explain each step along the way. There are many ways this code could be optimized to run better, but I wanted to keep things simple in the first few examples.
There is a lot of code duplication between the different examples which I felt was OK for the first few classes, but I will refactor some of the common functions into a utility class soon.
Update: I recently converted the example from using Epic’s ProceduralMeshComponent to Koderz’s excellent RuntimeMeshComponent.
All corrections, contributions etc are of course welcome! I’m still new to rendering in UE4 and ultimately want to convert some of this to using RHI calls myself (UPrimitiveComponent, PrimitiveSceneProxy etc).
Made some progress on animating the meshes, will post a couple examples on the Github later tonight.
Keep in mind that this is a very expensive way to do it since the mesh is generated on every frame! I will move away from the ProceduralMeshComponent later on for a more optimal implementation.
Hey SiggiG, I’ve been working on some serious updates to the PMC and would be interested in seeing what all issues you’ve been running into! That goes for anyone else as well!
I would love to hear what you have planned! I’ve been thinking about writing my own version of it, or going a completely different route.
What’s been bothering me lately:
The variables holding the generated data (mesh sections) aren’t marked as Transient. So if you offer editor support (not just generate on BeginPLay), all the mesh data is saved along with your map. I got around this by making the whole component Transient, causing issues with transforms among others.
No easy way to update mesh data once generated, so currently I need to re-create the mesh on every frame. We need a way to set a mesh as static (once generated) or dynamic. Perhaps allow updating the Vertices buffer, as long as length and indexes remain the same?
A way to export the meshes to static mesh assets. Antidamage posted a way to do this I plan on utilizing once I need it.
Well, if you’re interested, I’m in the Unreal Slack much of the day almost every day. (I’m in Eastern US, so not sure what timezone you’re in)
You pretty much listed some of the same things that bug me. The only one I hadn’t thought of was the mesh data getting saved, but I can probably solve that. I have far faster updates already done, as well as generally better render performance, and a few other things. I planned on supporting static mesh -> PMC, but not sure about the other way around.
I’ve updated all the examples using Koderz’s excellent RuntimeMeshComponent plugin. This is more efficient and faster than the UE4 ProceduralMeshComponent.
Hey SiggiG I have trouble getting the plugin to load with 12.5 …says the plugin was made with a different version of the engine and it wont rebuild for me!
Sorry for the slow response here. Hmm this is odd since I’m not providing a pre-built version of the plugin, only the source. I’ll take a look once I’m home.
Any luck, I’m breaking on 12.5 too. I simply can’t open the project if I have the plugin included.
EDIT: Nevermind - I was downloading from the wrong place. First I did the git repo direct, then from a link in the forum - but then I found the stable release (for 12.5 anyway):
Also - I had references to ProceduralMeshComponent in my project, which I pulled out. And I updated the Build file to show too.
Alright, new challenge - how to make these meshes have collisions. I’ve tried adding these sections to the initializer - but maybe I need to do something more.
What I suspect is happening here is not everyone being familiar with how Git submodules work? The example project is directly referencing a couple of plugins, and you can see the references pointing at specific SHAs here:
A submodule is like a sub-project, a way for a Git project to directly reference and use another Git repo. Unfortunately they aren’t super straight forward to work with…