Main concept
Creating pipes is something I have to do a lot. I really don’t know why I always end up doing that so much but I think that was part of the reason why I ended up creating this system.
It’s done in Unreal Engine, fully with blueprints. System is still at WIP stage but the main base logic is there, up and running.
If you think about it, pipes are not that complex in theory. Those pipes are just trying to move gas or liquid from point A to point B and that’s pretty much it. Pipes usually have to follow the environment so that matter can move from A to B and pipes usually also have to be out of the way most of the time so people don’t stumble on them. That’s why those pipes should have some turns to avoid obstacles like pillars, walls, roofs and other pipes. Easy way would be to simply use splines for this but usually pipes contains 90 degree angles so I would use splines for things like cables and hoses, not for pipes.
That’s why I ended up creating a mesh library that consists of 3 different meshes, middle, left and up. This is the minimum amount of meshes needed but it’s also possible to add more and the system will randomly choose different variations. Middle part will use a fill scale system to cover different lengths. Basically there are two thresholds: how much that middle part is allowed to scale down or up until it will add another middle mesh. This middle length value can be static, random from an array or fully dynamic based on a line trace to have more variation. Turns can be manual, random or something in between these two and based on that, the system will add up/down or left/right meshes. This is the basic idea.
User will generate a few different arrays that will drive the rest of the system. First will be the actual rule enum array that contains information about directions. Left, right, up, down or straight. Another float array will hold length values that are then used for middle parts. Loops will then break this data down, handle mesh instancing, transforms, materials etc.. This way it’s possible to save the results and edit them by hand if needed. It doesn’t matter how the system gets this information so it’s possible to manually input those values or use the automatic mode that I will describe more later.
Manual vs. automated
It’s trivial to place pipe meshes by hand as long as the actual meshes are modeled in a correct way using consistent rules for pivot points and scales. That will take time but then you have all the freedom to construct pipes. I really wanted to avoid that so my manual model is working like a gamepad. I used editor event buttons so the user can input what turns he/she wants, when to add middle parts etc.. Because the system is “array based”, it was very easy to make undo mechanics so users can delete the last action if needed. You can almost make a game out if this alone but it works pretty well most of the time for basic things. Is faster than placing meshes by hand and because the system also handles mesh instancing, it will also perform better. I wrote more about mesh instancing in my previous article.
Automatic mode is a step forward from this. It will use a pseudo random logic to figure out turns and when to add middle parts. There is also an option to turn on environment tracing so it can know when piping hits something and then figure out a way to avoid that. Automatic mode will use a simple number value to control how many steps it will run (pipe length). There is also an option to control alignment modes. System can built pipes in a planar fashion that is suitable for roofs or walls.
Because the system is using one main function so it doesn’t matter if you use manual or automatic modes because you can mix both. You can start with the automatic mode, then change to manual and after that continue with automatic mode again. I always want to have artistic control and this will give me that.
Pillars
In some cases piping needs support like pillars. This system is a separate function inside the actor. Basically it will use three different pillar meshes, start, middle and end. Middle part will again use the same fill scaling like the piping so it can handle different lengths. There is also a threshold value to control what is the minimum distance for pillars to appear or not. All of these parts are using the “Create HISMs” function logic that handles mesh instancing for me automatically.
Last part is to figure out locations where these pillars can “grow” from. I created a basic logic with dot products to see when the piping is “flat” so it looks more natural to have pillars. I also have an option to randomly delete pillars so it will not look that uniform and dense. Then it will simply use a line trace to figure out the length and construct pillars.
Socket based details
In some situations those pipes can leak or there might be something else hanging from them. How to handle this? Well I ended up relying on mesh sockets. Basically in Unreal, you can specify mesh sockets for each mesh. Then you can get those mesh socket names and find relative transforms. Loop will break down the socket information and uses the Create HISM logic once again to instance all of that.
Future ideas
At the moment this system’s automatic mode is pseudo random so it doesn’t really have any idea where it’s heading. It gives interesting results and different seed numbers will generate new results but it’s “stupid”. In my future plans I would like to add some sort of path finding system so it can generate piping towards a specific end goal.
Another thing I would like to do is to connect this with my building system so it would be possible to use it in a room to fill a roof. Scattering system is also something I might add there so there can be debris under those pipes.
This is still pretty generic system so you can use it to make all sort of things. Maybe even use it for some sort of dungeon generator or space station builder. I might go more in depth with this system in the future.
Until next time,
Kimmo K.
You can also find me in the following places too:
UE Marketplace Artstation Twitter Facebook Youtube
Very interesting to me! I use splines for my Sci-Fi tunnels, monorails, etc, but - such "pipes system" I also see as a good tool for Sci-Fi roads, tunnels, etc placement.