UE5: Building Structures - #2 Spline Walls Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello fellow Unreal Engine artists designers and developers in this series of videos we're looking at how to model structures within your levels and today we're going to start to create a spline wall system over three episodes we'll build a wall system that flexes and stretches to your Dimensions allowing curved walls and placing pillars and doors where you want them I'll show you the issues you might encounter along the way and how to resolve them so let's start off with the basic repeating wall [Music] the first thing we need to do is create a wall segment for our spline system so with your project open go into the modeling mode as I showed you in the last episode so or shift 5 on the keyboard and what we'll do is we'll create a new wall segment that's four meters by four meters and 20 centimeters deep so we can use the box tool for this click on that and we'll put it in the scene here temporarily let's zoom in a bit more if you press F on your keyboard it'll focus in and so we want to make sure we're outputting a static mesh we're going to make the width 400 centimeters the depth 20 centimeters and the height 400 centimeters and I'm going to apply the texture here as well so if I go down here and type brick I can use the damage brick wall that I downloaded in the last episode as well so you can see here that we have bricks on a dollar there um they're a bit large so let's change the UV scale so let's make it five and that kind of ties into what we did last week as well so um so we have a four four by four meter wall segment 20 centimeter deep with the brick texture applied click accept it's one last thing with the wall segment selected press Ctrl B to find it in the browser so select it Ctrl B and F2 to rename it and give it a name so we'll call it wall segment rather than the name it generates and then we'll be able to find it easily okay let's now create the spline wall blueprint so I've come back to the main selection mode by selecting up here and I've deleted the wall segment so we've got a nice clean floor for later on so let's start creating the blueprint for our spline wall system so control space and we'll go to the top level and create a new um folder here which I'll call tools and open that up and within that I'm going to create a new blueprint class an actor which we'll call BP spline wall and open that up and the first thing we need to do is add a spline that can be manipulated by in the editor so click on the add components type spline and we want not spline mesh but spline here and you can actually drag that up into the scene root as well just to make it a little simpler if you zoom out a bit here you'll see it's created a spline with two points here let's just make this four meters long so that it will generate one wall segment when we've put the code in so make sure your snappings set to 100 or one meter so at the moment we've got a one meter spline length here so click on the second Point here and drag it to there so it'll actually say 400 you see it's stress I'm dragging in 300 400 500. so I've created a two spline points and the distance between them is 400 centimeters enough for one wall segment okay we'll come back to this later so now what we need to do is start building the logic for calculating how many segments fit in our spline and then spawning them onto the spline so let's go to the construction script now and this construction script gets executed when you first drag a spline into a level and also when you make any changes like adding spline points changing variables Etc so first thing we need to do in our construction script is work out the length of the spline and how many all segments can fit in there so what we'll do is we will take our spline here so just do control down here which is components just do control to get the spline and if you do get length so you've got get spline length so at the moment we know that that is 400 centimeters but obviously we will be changing that and in order to work out how many mesh segments we need to divide it by the mesh length but we don't we don't actually have a mesh length variable at the moment so within variables click on plus and create mesh length and that needs to be a float and we'll make that visible so you can edit it later on we'll work that out we'll work that out automatically but for now we'll make it instance editable so that when you dread the spine and system you can set that value so click on compile and what we'll do is we'll set the mesh length here to 400 which is the length of our wall that we just created okay now we have that variable what we can do is we can work out how many of these meshes we can fit into our spline so to do that we can take the spline length drag out and hit the Divide key and divide the spline length by the mesh length so I'm going to drag the mesh length in and you will get a value but at the moment it's a float value so for example if this was 600 meters and you divided by 400 you're going to get 1.5 we actually just want to work out the integer value so in order to do that drag out here and use a truncate option and that creates that truncates the fraction from that and leaves us with a whole value and the last thing we need to do is work out if we have any segments at all in here so let's do greater than zero here so greater than and that's going to be our decision Point as to whether we need to do anything so Press B on your keyboard and click on some empty space that'll create a branch node and this is our first real execution node so we've done all these calculations and if there are more than uh if there's one or more segments here we're going to continue and calculate the or and go through and calculate all of the mesh positions okay so the next thing we need to do is we need to go through each of these options each of these points and spawn a mesh component so we will take our truncated value let's move this up a bit here so this is the number of meshes and we want to do a for Loop here so what we'll do here is clap right click do four Loop so you want a for Loop not a for each Loop because we're going through a set of indexes so we'll connect to the true here and the first index point the first point in your spine is point zero and then we want to go up to the penultimate point so we don't want to process the last point because there's nothing to stretch a mesh tape so at the moment here we have our values here so say we've got one segment if we've got one segment we want a process from zero to zero if we've got two segments we want to process from zero to one in in fact we don't want to do that we don't want to process the last one so we want to subtract here and we want to subtract one if we wanted to process the last point in the spline but because we don't want to process the last point we'll subtract two and then we'll connect that to our last index so this for Loop now is going to go through all of the possible wall mesh positions and now what all we need to do is for each of these positions or indexes we need to calculate where the mesh starts and ends and spawned so in our Loop body we will create a spline mesh component so add spline mesh component here and we can choose our mesh here so click on here and type in wall and there's our wall segment there's all sorts of other things here but we'll come back and look at those later on so for now we've added the the spline mesh component we then need to say where it is and start at n positions so drag off here and do set start and end and we need to now calculate the start position start tangent which is the direction it's facing and position and end direction so we'll come back and do that logic in a minute and the last thing we need to do is add the spline mesh component to the spline so we'll take our spline variable here and use control to drag it out and from the spline we drag off and if you do attach we want to attach component to component so that this spline mesh component is now a child of the spline and we need to make sure everything's connected up properly so let me just do this so our spline mesh component that we've added here we need to connect it to the set start and end and we also need in fact I've done this the wrong way around here the spline is the parent and the spline mesh component is the target so we're now connecting the spline mesh to the Target so the only thing left to do here is we need to set the start and end positions so if you remember we're going through an index of values so if we've got three points in spline we're going through we'll have index 0 and index one so we can calculate the positions based on the by multiplying the index by the mesh length and that will give us the distance along the spline and then we can use a function to get the position at that point so let's drag off this index and do a multiply and we will drag in our mesh length so for um the so for position zero zero times my strength will be zero and then what we'll do is we'll duplicate these two again Ctrl D here and we need to find out the end index that we're going to so to do that take the index do a plus and we want to add 1 to the index to get the next segment position and drag that in here so what we've got is the position the the distance in mesh length so if from zero to one this will be zero this will be 400 from the second point to third Point that'll be 400 and this will be 800. so that's the distance and now we need to find out where that is on the spline space so let's do it with the initial position first and there's a useful function here get distance a long spline so you want let's see if I get the right one here and get location at distance along spline and we're probably gonna have to create a bit of extra space here so let's take these nodes here and let's move them out a bit gives us a little bit more space to do these calculations okay so let's uh move this up here so this now gets us the position of the start point of the segment and if we use Ctrl D to duplicate that and we plug in the distance of the next point that will get the end position and what we can do now is we can plug those in to the start position of our set start and end and the end position and I'll just double click here to create some re-route nodes just to tidied up a bit okay so now we've got the start and end position of the spline mesh component we now need the tangents remember the tangents are the direction so this is telling us where the mesh starts this tells us which direction it's facing so that this mesh component can do the necessary curving from this direction to this direction so let's create a little bit of extra space here drag this down and what we need to do is now find the direction that the spline is going in at that particular point so if you drag out or just um drag from the spline again and do get tangent add distance along spline and we can plug the distance from the first point and then we'll duplicate that make sure you plug the spline into the target and now we're going to do the end distance in here as well okay and now we just need to plug those tangents into the start tangent and the end tangent here as well again just neaten that up a bit okay and so um now we have all the logic in place let's compile this and let's go back to our viewport and see what's happening so so at the moment if I drag around I can't see any meshes at the moment so let's go back to actually we haven't compiled yet let's do compile let's go back to our construction script and check everything and I realized I made a mistake in the beginning of the blueprint here when I subtracted 2. so if you think about this if there is one mesh in the spline and I subtract two this is going to try and go from index 0 to -1 so I should have just subtracted one here so let's click on one compile let's go back to our viewport and what you'll notice here is the first issue that I want to address is quite a common thing so you see that it's actually put our mesh in here but it stretched it along the long part of the wall instead of the thin part of the wall so we need to address this issue and then we'll carry on with the next part of the tutorial so I've come back into the construction script and if I look at the add spline mesh component and we look at some of these parameters here you can see by default the forward axis for this component is the x-axis which is the default for spline meshes and it's uh up on the z-axis as well now you can change these I mean if if your meshes are in the wrong axis but I'll be honest with you there's a world of hurt if you start to play around with these my advice to you is to make sure your meshes are aligned the length is aligned along the x-axis so if we browse to our wall segment here and open it up you can see that the way we created it using the box tool and and its definitions of width and depth it aligned it along the y-axis so we really need to rotate there now you can't just rotate it um in the level you need to make sure that rotation is fixed in the mesh so I'll quickly show you how to do that so let's come back to level here and let's just drag in the wall segment so it was in your model generated models folder so drag it in here temporarily and what we'll do you can see there it's along that's the y-axis there so what we will do is we will go into modeling mode again we'll select our select our um segment here make sure rotation snapping is set on go into the rotation tool you can either press e on the keyboard or just press space if you've got it selected and rotate it around 90 degrees so it's facing down the x-axis and now in order to make that stay as the default for this mesh you go down to the in the transform section bake rotation and scale so what that will do is that will make this the new default rotation start and scale start position so click on accept nothing's changed here except that if you look at the mesh in the mesh editor this will now be along the x-axis so that's exactly what we want so let's do a quick save shift one to come back from section mode actually we don't need that in the level anymore okay let's go back to our spline wall system and go back to the viewport and that has now been resolved so you can see that the all is in the correct orientation and we should be able to drag out the spline here so select the spine first then select spline point and if you drag out when we get to 800 a new one appears so you can see every time we get to a multiple of 400 we're getting a new it's a wall segment so the basics of this are working so let's actually create a Warner level and I'll show you the basics of manipulating spline points in your level so let's create our first wall using this new tool in our level go into the browser into our tools folder here's our BP spline war and we'll just drag it out onto the level here so I'm going to drag it here and you see that that's our level with in fact I left the I left it dragged out here so I think we've got two wall segments here so you can click to select the spline and then you can click again to select particular points so you can see that as I select the points you get the gizmos on there and we can drag things around so just as we did a second ago so that's that's one wall segment no wall segments one or two and if I want to add uh new segments to the spline I can just press the ALT key and drag off this spline point so if I do alt here and drag you see we're getting a new spline Point here and I can then move that if I wanted to create spline points in between points I can drag on one and still do alt and drag a new one in between and then we can work on that but you you'll notice an issue here which is that we're not getting curves we're getting very angular um differences between the points and the reason for that is because we haven't got enough geometry in our wall at the moment so if I put the wireframe mode on here you can see that our walls here only have one plane two triangles so in order to um stretch the wall around a curve it would need to have more geometry along the x-axis here so let's show you how to resolve this issue let's go back into lip mode and we'll we'll leave that spline there we'll come back to it in a second but what we'll do now is we'll edit our wall segment to add more geometry along the x-axis so in order to do that you go back into your models let's pull our wool segment in here and we need to do some more modeling on this so go back into the modeling mode here and what we could have done is when we created if we if we'd have known when we created this box we could have created it with first of all the right Dimension so we didn't have to rotate and we could also have done subdivisions along the length of the wall by changing this to say 16. some of that but if you ever need to do fixes for meshes that you've been given I don't have that it's useful to know this technique as well so what we're actually going to do is we're going to go into oh let me come out of that we're going to go to the poly edit mode and you can see that it shows now the different parts of the mesh and one of the options we got here is insert Edge Loop and what that does it allows you to insert um Loops that segment the mesh now what I want to do is I want to divide this into 16 equal one so what I'll do is I'll make the position mode even and number of Loops we'll do 14 so effectively the N2 plus this means we've got 16 parts and if I now click on here you can see that if I hold near the top there I've got 14 evenly placed Loops here click on that click on accept and we now have the extra geometry here and if you see if I zoom out and go over to my spline wall you can see now it's no longer angular it's nicely curved around those points so that's worked really well so let's um come back to the selection mode shift one let's get rid of the wall segment here we don't need that anymore and let me just show you a couple of other things to do with the manipulation of spline points here so you've already seen how you can create points move them around so just drag them move them around but if you want to adjust the curves of segments you've got a couple of options so let me select this one for example so you can see here these are the tangent points here you can adjust those but you tend not to need to with the tools I'm going to show you so at the moment this is the tool for moving if you press the space bar it changes to the rotation tool so you can now rotate the curve in the spline and the last thing you can do if you press space again is you can scale the spline so by scaling it if I zoom out of it it's not always easy to do here so I'm holding the middle here if I zoom out a bit it creates more of a stretch in fact it's probably easy to do with the snap office take the snap off and there you see as I drag out the curve gets wider and as I drag in the curve gets narrower but there is a problem with this spline system at the moment so I'll see if I can show you the issue and then we'll resolve it so let me um add another spline Point here so I'm going to use alt and drag out another point so we've now got a curve here and if I make this a wider curve what you'll notice is that so let's see if I can show you this yeah you can see that as I get to a certain length it's no longer curving it's sort of distorting and that seems to happen when you have longer gaps between the spline points so let's address that issue in the blueprint I'll tell you why that's happening and how to fix it so I'm back in the blueprint here and you remember I told you that the tangents here tell you the direction that the start and end points are facing now the thing with the tangents is they're a vector that not only tell you the direction but they also have a length as well and what happens is when that length gets larger than the length of the mesh it causes that Distortion that you're seeing in the uh in the spline that we just created so what we need to do is we need to make sure that the the direction is preserved but the the length of it is no longer than the mesh length so luckily there's a single node that can do that if we drag out of this tangent node and do a clamp and you see you've got a clamp Vector size here so what we want to do is we want to clamp it between a minimum value of one which is the normalized vector and the mesh length that's the maximum so let's just drag the mesh length from our components in here and then the output of this will now connect to our start tangent and let's duplicate this and we'll connect our end tangent to the same constrained so we'll take our n tangent and clamp it to between one and the length and then attach it to the end tangent and so that will prevent any Distortion happening when calculating the start and end tangents here so compile this let's go back to our scene and you can see straight away that Distortion at the end where it flattened it out has gone and we've got a much more sort of bezier curve in that spline okay so I just want to um talk about something else here now as well now you so far you're seeing beautiful curves here but what if you want to have an angle between a sharp angle between points like you want this to come in here and then to have a sort of a Sharp angle between that wall and this wall so there are two types of tangent Types on a point so if I select this one here and right click and look at spline Point type I'm sorry um automatic tangents at the moment it is an unclamped tangent that's the default and that means that it has those tangent handles that you can adjust a clamp tangent would affect you to reduce those tangent handles to zero I'll do it here and it will create an angle now the problem at the moment and we're going to address that in the next episode is that it can't do a sharp angle if it's Midway through a mesh you can only do a sharp angle if a mesh ends and a new mesh starts at that point I'll show you what I mean if I delete this point here you can see here I've now got a sharp angle this is because this is 800 long and so the mesh ends there and a new mesh starts there if I click this and drag it you see as I drag it I'm getting a curve when I get back to 400 actually I'm not going to be able to do that let's control Z let's put the snapping back on so as I go 700 600 I'm getting curves 500 curve when I get to 400 it snaps again because the mesh ends here and the new mesh starts there so what we'll do in the next episode is we'll actually calculate the meshes to go in between two points so that meshes always end so we'll do a bit of stretching and shrinking as required here so let's as a final thing just um just to get prepared for the next episode let's just do a bit of commenting in our blueprint so that we know what everything is so let's start off with the this section here comment it and say calculate number of meshes in slime and then I'm going to drag this into its own area see for comment and I'll call this calculate start and end mesh details and then finally comment around here and I'll say add spline mesh component and this way we're in a I'll sort these out in a second this way we're in a better place for doing our enhanced spline wall system in the next um next episode so I hope you found today's tutorial useful as I said we'll continue to build this out uh to allow proper scaling and stretching between points of these walls in the next episode and then in the episode after that we'll look at adding other segments such as sort of pillars at angular points and doorways in the selected segments of the wall so stay tuned and I'll see you in the next one bye for now
Info
Channel: UnrealityBites
Views: 32,364
Rating: undefined out of 5
Keywords:
Id: pg8gx20jnOI
Channel Id: undefined
Length: 31min 57sec (1917 seconds)
Published: Tue Jun 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.