Baking procedural content.

So as I understand it, procedural content does not benefit in any way from baking light maps and so on.

I’m greedy. I want to have my cake and eat it as the saying goes. I want to procedurally generate content, either within an UE context or externally, and then in some way get it baked by UE.

My initial approach was to generate a static mesh using FBX SDK for the basic terrain, and then import it into an empty project using the UE command line. So far so good, and I can even simplify that by having all the materials already in the project’s content and then referring to them in the FBX file, rather than having to define them in the FBX file itself. I can then bake that using the command line! Hurrah!

However, I need to manually add the imported terrain asset into the level. Maybe I could have another asset with the same name in the map file, and then replace the original asset with the imported one. The map file will never know the difference.

But…I still need to add props. Chunks of rock, trees, bushes, or whatever. And monsters to fight. And so on. Lights! I need Lights! And not just sunlight shining down from above.

So plan B is to modify my FBX program to import all assets from other FBX files and create a full scene. Everything all in one, and then somehow import the whole scene, in FBX format, as a level. it seems workable.

But…when experimenting with particle effects, UE does not export or import particle effects to FBX format. At all. I created a scene with a particle effect, exported to FBX, re-imported, and the particle effect was lost.

Does FBX not support particle effects? I thought it was supposed to be able to support entire movie scenes!

So…new plan. Export the terrain mesh as an FBX file, and import as an asset as before. Then reverse engineer the UMAP file format and generate my level as an UMAP file.

But…that looks like a REALLY big job. I have, with some success, reverse engineered binary file formats before. It is not easy and is probably illegal. It is extremely time consuming. I mean HUGELY so. If I worked on it 8 hours a day it would probably take a week to get something that worked ok most of the time. Maybe longer. I have a day job. I do not have that kind of time available.

Does anyone else have any ideas?

I don’t know much about FBX, but Unreal supports text-based a export/import format (t3d) which is quite easy to understand and leverage.

You can export an entire level via File > Export All, and pick Unreal world text (t3d) format. Or you can export specific actors (one or multiple) by selecting them and ctrl+c / ctrl+v into a text editor.

You can import actors into level by pasting text into UE viewport.

It should be much easier than trying to reverse engineer binary format, however if your plan is to automate the whole thing (command line) without launching UE, you might have to write a Commandlet (requires C++) to programmatically create a level, import the data, and save the package.

2 Likes

Chatouille, you are awesome. I think that gives me everything I need.

I need to figure out more about how to use packages, but I could:

  1. Run my command line program to turn my level file into the terrain mesh in FBX format.
  2. Also have the command line program generate a t3d level file.
  3. Run my commandlet to import the FBX for the terrain mesh and the t3d level file and save as a umap.
  4. Use the UE5 command line to bake the whole lot into a package, or, if I can figure out how to get my commandlet to do it, bake the level into a distinct package.

A link to a good article on how baked content is packaged would be great. I think I ideally want all materials, particle effects, and static meshes to be baked into one package.

I have found a very few articles about writing commandlets, but they all refer to the code I need to write. How do I build it? Do I need a “uproject” file? I see that plugins use a “uplugin” file? Do I need a “ucommandlet” file instead? What module files do I need to add? What should be in them?

I found a UDK “hello world” example, but no instructions on how to build it - that seems to be assumed knowledge. I also found forum posts saying that that example did not work for the OP. Specifically when he tried to run his commandlet it complained about a lack of a map. As I am trying to use a commandlet to create a map…that could be a problem.

In a spirit of hope I fired up Unreal Editor and tried to create a new project for a commandlet - but couldn’t find a suitable option.

I could really use a bare minimum set of all files for a basic hello world commandlet compatible with UE 5.6 (I’m a bit behind), especially project files and module files and so on. I can figure out the rest myself from there…probably.

As far as I’m aware you just need to create a UCommandlet subclass in C++, it doesn’t require anything specific, but of course you’ll need a C++ project.

If you don’t have one, boot up UE launcher and create a new empty C++ project. That’ll give you a foundation with a “uproject”, sources directories, and a VS solution. You can manually add new .h and .cpp files in the sources, and regenerate project files (right click on .uproject) to register the new files. Then write your commandlet subclass, and compile.

There’s one sample there https://github.com/ue4plugins/CommandletPlugin however it’s a plugin and it’s UE4. Would probably have to be fixed a bunch for UE5. Instead of bothering with a plugin you can just add the commandlet to the main project.

The commandlet is an awesome idea. When reading up on it I realised that the FBX importer I was using was a commandlet so then I dug around for the code for that and now I know how to turn my data directly into a uasset file.

So my plan now is to have a commandlet that turns the basic mesh into a uasset file, and then generates a level which includes all the static meshes and so on, and then save that. I may even do all the baking and so on within the same commandlet, but maybe not.