Spline Mesh Components and Instanced Meshes for Faster Level Design in UE4 Blueprints

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when i started making video games the first thing i fell in love with was level design i really loved piecing together levels to create entire worlds but i quickly ran into problems when i individually placed things and tried to attach and align them together it would just not work even with the copy paste functions i was spending so much time fiddling with placement rotations trying to lock things together and that's when i knew there had to be a better way i ended up discovering two techniques of placing meshes that changed the way i make levels it saved me hundreds of hours and even increased the performance and i'm excited to share this with you today so let's jump in so let's go to the first one the first one is the regular spline mesh so this tube here is a regular spline mesh uh it uses a spline mesh component we'll look at the blueprint after as you can see when i move the tangent i can cause deformation i can also trigger a random coloring which uh happens every time i move or add sections in terms of lods we can see that each individual object has its own lod see we have one two three exclamation marks and then we're missing the dot and then you can't really see it further but there's deformation and in fact the whole exclamation mark disappears so let's take a look at how it works so everything is done in the construction script all you need to do is add a spline itself and let's go through it uh the first part here is set the section length so the section length will define in a length of the spline how much of it is a section for your mesh the reason we create this is to only create meshes if the spline is extended past that threshold of the section length so here if i go back to my tube i can extend this but as long as i don't pass the section length threshold it won't appear that's because i want to add to it i don't want to deform or stretch out an existing section so here we just get the active scale 3d we're looking at the x-axis and we're going to get something called the section length coefficient which will be calculated later when we define what the spline mesh component is and then we set it up afterward we're going to calculate the length of the spline divided by the section length to determine if it adds a measure or not so this is how we do it get the spline get the length divided by the section length truncate it and minus one of course and we will because we're using uh indexes or indices and then we're going to go for a for loop so each time we add something it's rerunning this operation and the construction script okay so here's a little bit of code i had to put in [Music] i put a switch based on an integer uh for one mesh or another unfortunately i have not figured out if there's an easier way to assign the spline mesh component mesh other than hard coating it but this seems to work fine you can make your switch as big as you want you can make it into an array etc you can actually make this to a more complex function if it's zero it's a crate if it's one it's a pipe once we defined what our mesh component is and we added it so add the block make sure that the forward axis is in the x direction and set up more defaults uh we can then uh use this calculation here which is get the spline mesh component get the static mesh out of it get the bounding box from the static mesh and then measure the minimum and maximum x values find the difference and set the section length coefficient to it make sure that you subtract from the maximum the minimum afterwards you no longer have to manually set this variable it will auto set itself here is a little bit more complex spline meshes unfortunately the component needs more definitions than just adding it he needs to know okay where's my beginning where's my end how far is my tangent what do i do with all this and this is basically how it all gets defined here i could go through it but it is exceedingly long and does not actually add any value to this tutorial and then finally once you've defined your static mesh component you can actually change values off of it um set the collision the collision channels the color scheme and then set the material from the color scheme here i just made a quick switch based on the enumerable where based on the selection pick either yellow green blue red pink or random and then output the material and that's what you get the next one we're going to look at is the hierarchical instant mesh it basically builds the hierarchical static meshes on top of the spline or following the spline now as you can clearly see there's an issue here with the deformation it does not deform as intended so that's that's going to be a drawback so if you need deformation like in pipes you're not going to be able to achieve it here another issue is although you can change all the colors you cannot change random individual colors and finally uh the lods as you can see each one of them has its own individual lod let's take a quick look at the blueprint again um here i actually managed to set the static mesh in the beginning and making it into a public variable so when you bring your hierarchical static mesh actor into the scene you see it's empty but then we can assign whatever we want to it and it will just change to that change your mind change it for something else once we set that up again get the section length coefficient but since we already defined the static mesh here we don't need to do it later we can do it earlier and then define the section length once we have our section length divide the spline by the section length and then for each of those dividends we're going to do a for loop we're going to add to it so notice i have a spline and i have a hierarchical instance mesh component we're going to take that same component and just add an instance to it and we're gonna add it at so here we don't actually have to define the beginning ends or anything else we can just define the transform get the location along the spline easy enough you can just multiply the current index with the section length and you'll know exactly what position it should be at make that the new transform and here i've added a miscellaneous color scheme function to change the color and that's it the final one we will look at is the instant mesh so the first thing you'll notice is that the lods are consistent across the entire object there's no individual lods and that's one of the drawbacks of the instanced mesh there is nothing else to add to this explanation it is the exact same blueprint as with the hierarchical one with the exception that it's going to use the instant static mesh component instead of the hierarchical instanced static mesh component and everything else is exactly the same so this is all great we kind of see what some drawbacks are for some and what some advantages are for others so for the spline you can force deformation you can have individual properties whereas for the hierarchical instance match you can't but it does hold individual lod properties whereas the instant static mesh does not do any of that it just makes the thing so now we're going to take a look at performance so again tilde stat scene render and tell the stat units or units sorry let's get the fps also so at risk we have about 120 fps uh eight milliseconds each well the mesh draw call is at about 11. if we turn around and we look at this beautiful scenario the draw call spikes to 180 and our frames per second drop to about 60. the draw thread which is on the cpu is bottlenecked not the gpu the reason that the gpu is high is because it is synced to the frame time but the real issue is the draw thread if we improve that by reducing draw calls the gpu will follow now let's compare the hierarchical instanced mesh so again at rest we have the same values as before 120 fps uh mesh draws 11 and then we look at this beautiful thing mesh draws only go up to 23 and we're still maintaining 100 to 110 frames per second the results are very encouraging and due to the deformation we're also allowing the system to work much better finally we have the ism for the instanced static mesh here we can see we are saving a couple of draw calls uh unlike the hism so we get 19 instead of 21 mesh charcoals due to having a single lod however there are more polygons for the gpu to render usually the extra draw calls in hism are worth the performance increase on the gpu side but in the end it's up to you to decide which trade-offs are appropriate for your situation here's an example of using spline meshes in a super metroid slash mega man like prototype we've been working on as you can see the majority of the level is built using the spline meshes rather than individually placing blocks so let's see here we have a floor and in it i also added something to define what the mesh is central wall floor or as a wall or floor from another level i can change it to a wall and it will immediately appear as such but notice that the anchoring is set to match with the floor and if i pick the ceiling it will be on top so if you have meshes that are set up this way then you don't have to continuously reposition them every time so i'm going to make a little copy here holding the alt key and wall let's make another copy and ceiling and i basically have a corridor from a side view fully done in three clicks thanks for watching what method would you use let us know in the comments below please like and subscribe for future videos and finally consider supporting us on patreon for exclusive content and other perks see you in the next one
Info
Channel: Pending Kill
Views: 30,279
Rating: undefined out of 5
Keywords: unreal engine, tutorial, gamedev, unreal engine 4, unreal engine tutorial, unreal engine tutorial for beginners, unreal engine tutorial blueprint, unreal 4 tutorial, ue4, coding tutorial, blueprints, epic games, blueprint, performance, profiling, draw calls, frame rate, scenerendering, stat fps, stat unit, ue4 tutorial, game development unreal, unreal game development, spline mesh component, spline, hierarchical instanced static mesh, instanced static mesh, hism
Id: ulb4escy8Yw
Channel Id: undefined
Length: 12min 8sec (728 seconds)
Published: Mon Aug 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.