Mortus
Veteran
Hello, I was looking through a forums searching for any AI mesh tutorial or at least some info but didn't found much. Maybe my searching skills are not so good but anyway, I decided to write one.
I was thinking about placing this thread in the main mod development forum but then decided that here's a better place for it. Custom settlements is one of very few mods where AI mesh editing skills is very important not only for mod developer, but to other users, because they are actually creating scenes for it. I noticed that many people don't understand the AI mesh concepts, some of them don't know how to use it correctly. It took some time for me to understand some basics about it so I'm sharing this experience with you. Please note that almost everything mentioned in this tutorial is consequence of my own observations and testings and not everything could be actually right.
Also, please excuse my English, if you want to make this tutorial looks more literary, feel free to PM me, I'll edit the post gladly.
There's also one more thing to mention before we start. Many people have their game crash when in AI mesh edit mode. There is few ways of preventing this if you have the problem. First, always edit AI mesh in "Scene Editing Mode (Cheat)", you can enter it by pressing "Enable Settlement Edit Options" while camping on the world map, the option will appear then in the settlement menu. If it won't help, then try not to move the camera while in AI mesh edit mode, switch to Object Edit or any else, move the camera, then switch back. That helped me for some time, the game didn't crashed not once, but then something changed, I'm not sure what exactly, and crashes returned. If nothing helps, try overwriting one of Native settlements with your scene (don't forget to edit scenes.txt) and edit AI mesh in Native. Maybe there's something in this mod causing the crashes, I'm not sure, but it helped for me.
Part 1. AI mesh basics.
I think I won't stop on how to enter AI mesh editing mode and any basic controls of it, it's very similar to another editor controls. You can check for info about it in "Settlement Scene Making Guide" sticky thread by wickedshot. Also, in part 2 of this tutorial I'll give an example with some of the functions explanation.
So what is AI mesh and how it works?
AI mesh is a grid used by NPC's to find a way from their location to their target location. For example, if NPC at point A wants to go to point B and there's no straight way there, he'll bump into building/fence/whatever is located between A and B and will stuck there forever. But if you use AI mesh, NPC won't use that straight path to reach destination, instead, he'll search for the shortest way within the AI mesh ignoring everything else.
Important note
All faces of the AI mesh should be interconnected to work properly. That means you cannot create mesh inside the building, then another outside, don't connect them and hope everything will be OK. Also, they must be actually connected to each other, not only placed really close. Here's some screenshots.
Right, NPC's will pass there:
Wrong, NPC's won't use this entrance:
You can connect two different faces with "fill" function while editing in vertex mode.
It is important to cover as much of the places where NPC's could walk as possible with AI mesh. Here's some examples of good AI mesh placement (screens taken from Native scenes):
Note how AI mesh is located on the stairs:
Try not to use difficult patterns while placing your AI mesh. I believe that AI mesh build of squares is generally good. Don't place too big faces, try to break them to several smaller ones. Also, don't use too many small squares, I think that can slow down the game maybe. Plus, placing big faces in one part of scene and small ones in another could result in unpredictable consequences. Here's an example:
I've placed 30 and 31 entrypoints to the point A and 32-39 to the point B. NPC's have two paths to reach from A to B as you can see. And as you can see, they chose path 2 because they think that it's shorter. And it's actually shorter in AI mesh means because there's fewer faces in it than in path 1. Try avoiding that in your scenes.
Part 2. AI mesh placement in constructions.
Let's get to some practice at last.
I've got a scene with AI mesh over the terrain here and want to place a castle on it. So I'm placing "castle_f_gatehouse_a" and switching to the AI mesh edit mode.
Right now, I need to delete faces that are under the castle so NPC's won't try to go through it's wall. Pretty easy way to do it is to select one face, then click "Grow Selection" button few times for all the faces you can't see under the castle will be selected, then deselect faces you need to keep. At that point you'll see that:
Now, delete selected faces and move remaining faces' vertexes closer to the building:
(maybe it's not the best way to design mesh and you should had added some more faces to fill the remaining space but it's pretty easy so I'll stick to it for now)
You'll want NPC's to go through the gates, right? You need to place AI mesh inside the entrance then. But you don't have enough vertexes to make a pass, switch to edge mode, select edges close to the entrance and press "Subdivide" button. The result would be something like that:
Now make the same at the another side of the gate and move the vertexes to the pass:
Select the edge that's closest to the pass and press "Extrude" button, move the new created edge further to the pass, adjust it's size, make the same at the other side:
Switch to vertex mode, select all 4 vertexes that must be connected and press "Fill" button:
Congratulations! You've finished with the easy part. Try to do it more accurate than I did though so NPC's won't stuck at the corners.
Now you need to make mesh leading to the roof of this building, subdivide and extrude another edge, I won't repeat that in details, that's what you want to see at the end:
Extrude the edge near the door two times, make sure that it's not wider than the entrance so NPC's won't stuck, also check it's z-coordinate, it must be on the floor, not under the ceiling.
Select two edges facing to the ladders, extrude each two times, move new edges so it looks like that:
Select, extrude, move, select, extrude, move, I'll stop at the moment edges will reach the top step of the first ladders:
You can notice that I added some new faces on the first floor at that point too.
Now you'll want to make a turn, extrude another edge, switch to the vertex edit mode and select two vertexes on the different corners:
Press "Connect" button, you'll see a new edge connecting selected vertexes, now delete face that's inside the wall so NPC's won't try to go there:
Move vertexes, extrude, extrude again, you know how to do it already, make your way to the top of the tower (don't forget to use "Fill" to connect faces coming from different ladders):
I'll skip the remaining process, don't forget to make the same operations with another entrance (this tower have two of them). At the end, place entrypoints 30 and 31 on the top of the tower and 32-39 near it's entrance, add some prisoners to the settlement and check if they can get to the top of the tower. If they stuck somewhere - you'll need to edit mesh there. It's important to add AI mesh to every place where NPC could possibly go. One can follow you in the battle and end up at the top of some tower without AI mesh. If that happens - he won't be able to return back neither other NPC's will be able to find him and kill.
That's a final screenshot I made when all (half actually, I didn't yet added AI mesh to the another entrance) the work is done. Try to test with slaves every pass that you've made (that's what they are for after all).
That's it for now. I hope this tutorial was useful for someone. Feel free to add something, I'll edit this post to make it more informative. Hope there was not too much images and it was not too detailed.
I was thinking about adding part 3 - AI mesh in cities, do you think it would be useful or is there nothing to actually talk about? Anyway, please leave your comments on this one and maybe one day we'll make this tutorial really good and worth reading.
P.S. MANY travellers came to my village while I was making this tutorial:
I was thinking about placing this thread in the main mod development forum but then decided that here's a better place for it. Custom settlements is one of very few mods where AI mesh editing skills is very important not only for mod developer, but to other users, because they are actually creating scenes for it. I noticed that many people don't understand the AI mesh concepts, some of them don't know how to use it correctly. It took some time for me to understand some basics about it so I'm sharing this experience with you. Please note that almost everything mentioned in this tutorial is consequence of my own observations and testings and not everything could be actually right.
Also, please excuse my English, if you want to make this tutorial looks more literary, feel free to PM me, I'll edit the post gladly.
There's also one more thing to mention before we start. Many people have their game crash when in AI mesh edit mode. There is few ways of preventing this if you have the problem. First, always edit AI mesh in "Scene Editing Mode (Cheat)", you can enter it by pressing "Enable Settlement Edit Options" while camping on the world map, the option will appear then in the settlement menu. If it won't help, then try not to move the camera while in AI mesh edit mode, switch to Object Edit or any else, move the camera, then switch back. That helped me for some time, the game didn't crashed not once, but then something changed, I'm not sure what exactly, and crashes returned. If nothing helps, try overwriting one of Native settlements with your scene (don't forget to edit scenes.txt) and edit AI mesh in Native. Maybe there's something in this mod causing the crashes, I'm not sure, but it helped for me.
Part 1. AI mesh basics.
I think I won't stop on how to enter AI mesh editing mode and any basic controls of it, it's very similar to another editor controls. You can check for info about it in "Settlement Scene Making Guide" sticky thread by wickedshot. Also, in part 2 of this tutorial I'll give an example with some of the functions explanation.
So what is AI mesh and how it works?
AI mesh is a grid used by NPC's to find a way from their location to their target location. For example, if NPC at point A wants to go to point B and there's no straight way there, he'll bump into building/fence/whatever is located between A and B and will stuck there forever. But if you use AI mesh, NPC won't use that straight path to reach destination, instead, he'll search for the shortest way within the AI mesh ignoring everything else.
Important note
All faces of the AI mesh should be interconnected to work properly. That means you cannot create mesh inside the building, then another outside, don't connect them and hope everything will be OK. Also, they must be actually connected to each other, not only placed really close. Here's some screenshots.
Right, NPC's will pass there:
It is important to cover as much of the places where NPC's could walk as possible with AI mesh. Here's some examples of good AI mesh placement (screens taken from Native scenes):
Try not to use difficult patterns while placing your AI mesh. I believe that AI mesh build of squares is generally good. Don't place too big faces, try to break them to several smaller ones. Also, don't use too many small squares, I think that can slow down the game maybe. Plus, placing big faces in one part of scene and small ones in another could result in unpredictable consequences. Here's an example:
Part 2. AI mesh placement in constructions.
Let's get to some practice at last.
I've got a scene with AI mesh over the terrain here and want to place a castle on it. So I'm placing "castle_f_gatehouse_a" and switching to the AI mesh edit mode.
You'll want NPC's to go through the gates, right? You need to place AI mesh inside the entrance then. But you don't have enough vertexes to make a pass, switch to edge mode, select edges close to the entrance and press "Subdivide" button. The result would be something like that:
Now you need to make mesh leading to the roof of this building, subdivide and extrude another edge, I won't repeat that in details, that's what you want to see at the end:
Now you'll want to make a turn, extrude another edge, switch to the vertex edit mode and select two vertexes on the different corners:
That's a final screenshot I made when all (half actually, I didn't yet added AI mesh to the another entrance) the work is done. Try to test with slaves every pass that you've made (that's what they are for after all).
That's it for now. I hope this tutorial was useful for someone. Feel free to add something, I'll edit this post to make it more informative. Hope there was not too much images and it was not too detailed.
I was thinking about adding part 3 - AI mesh in cities, do you think it would be useful or is there nothing to actually talk about? Anyway, please leave your comments on this one and maybe one day we'll make this tutorial really good and worth reading.
P.S. MANY travellers came to my village while I was making this tutorial: