Unreal Engine 4 Tutorial - Splines - Spline Meshes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone and welcome back for another tutorial video in ue4 in this episode we're turning to the splines and looking at this time how to make a spline meshes now spry meshes are really cool powerful tools to allow you to create procedural meshes in your game environment so these pipes I've made here so I've made this one here and I made this big one here which you can actually run on as part of the geometry okay so we'll go through how to make one of these and how it works so you can tweak it and change it to suit your needs ok so let's first of all delete what we've got here then we can start getting from scratch okay so to begin with the spline measures your first we'll need a mesh now the mesh I've got here is a pipe and I'll open it up first simple pipe are made in Maya very quickly and the only thing you need to make sure you have of your mesh is that in its wireframe you can see here that you've got multiple segments to it in its length okay the more you have the more accurate the bend will be so it'll it'll warp and change this shape of the mesh they can only do that if it has enough segments so if you find that you're getting a lot of breaking geometry and when you're doing this it's probably because you haven't got enough of these points here I see I've only got five sections one two three four five so that's plenty for me it's been nuts of it it'll be quite conservative with it if you need to be so for that for this to work we need make an actor so make a new blueprint class actor and I'm gonna call pit pipe spline and want to open it up so we the race works if you followed along with the last a spline video we've done is we use a spline and to do that you got to add components and type in spline they don't want spline mesh not yet anyway you want spline now a spline for those who do watch this video essentially it's a line that is dictated its shape by the number of points on its line okay so if you ever use the pen tool in something like Photoshop or illustrator it works exactly the same as that just in a three-dimensional space so the way this works is that you will drag out the spline to create a pipe in this case of pipe shape any kind of shape you want and this will happens on the construction script and the construction script basically runs whenever something about this shape changes or is spawned into the world and it's very useful for making procedural stuff inside the editor so for this to work with a collection script we have to use a spline so drag your spline component into your event graph to get a reference to it and the way we're going to do it is we're going to get the number of points we have on a spline so this one has to when it start one at the end and we're going to a for loop as many times we need to so this will get the number of points we have so drag out a spline and tapping get number of spline points and that returns an integer number of hami spline points it hats so by default it will stick out at two okay one start right at the end from the construction script node we're going to go to a for loop and the for loop will go through as many times as dictate here on a loop so the first minute we zero the last index will be the number of spline points however what I want to do is change this value slightly because if I look at my spline points here I've got one two spline points for one section so to get one section drawn into this by default I need to take one away from the spline points so I'll take away and it's Joe of one unplug its last index that means it will go from index 0 and index 1 to a dass prime mesh however our not quite happy with that because if it's going to add a sublime pointer index to 0 that's this one here and the next one we should be spline point 1 it's an edit Spri mesh here as well which I don't want I don't want it to have a little tact on bit here so I'm gonna take another one away from it so I only get one point being spawned at point 0 so in your number of spline points it's going to take away 2 and that's going going to your for loop okay so in the for loop we're going to now add a spline mesh so copying add spline mesh now spy mesh is a mesh that can be bent basically usually along a spline but you can bend it slightly using a tangent okay so that's what that is we've it selected you need to choose which mesh it's going to use so from the drop-down choose your mesh my case pipe and then have a return value the return value is that component we just made okay so this is the output return value with the return value we're going to set a couple of things so first I'm going to do is set it's a forward axis and this determines which direction it's going to be going if you're unsure which of their directions it's going to be open up your mesh look at this which way it's facing and then look at the little gizmo in the corner and you can see this one in my case is going in the x-axis it's going X along there okay if it's going that way it would go in and the y-axis but it's not so it's in the X so set forward axis will be X and then also from the return value drag that out to topping set start and end in the set style end and allows you to change how it's a starting point and its end point and determine how it's going to bend accordingly so you've got load of vectors here we need to input and that's what I'm gonna do next so the way we can do this is we're going to access each point on the spline so drag your spline in from the component list from there you want to type in the words get location at spline point and the spline point we need to point in next and that will come from our for loop so index will go into here I was going to add a little reroute in there like so are also going to need the tangent start position start tangent and I can do that too just drag out from the spline a topping get tangent at spline point again hooking up the point index to my little blue roots here now these two can go into the start position and start tangent now to the end position I want to get the point index the next one along so this is for example point zero I need to get to now point one the one ahead to get the end position so to do that you drag from the river and go add one and do exactly the same again before so spline here and I'm just gonna copy and paste these two here and hook these up exactly the same but this time go into the end position and the end tangent like site and click compile and that's it we're done I'm gonna drag this pipe spline into the world and there you can see it there and the way works is you have the point C which you can click on the red dotted lines and these are the handles of the tans I say control the bend of it but you shouldn't need to touch them too much so I can grab the end here and I can move it and you can see it force easily changing the shape of the pipe as I go if I wanna make another point I just hold down the Alt key and move it up and you can see the spline now bending based on what I want to do I can rotate these a little a little bit as well and you can make the various shapes as you can see has no collision on it but we can add collision to it quite easily just open up your pipe spline component an actor and somewhere after the return value of this primus component drag that out go set collision enabled and hook it up like so and the type of collision we want is collision enabled the bottom one and now it's got a collision on it so come on around it ok now next is to make it a bit more advanced because at the moment if I think that I'm putting up on in and show you what's wrong with this we're something like a pipe I don't want it - I want it be uniform and consistent so if I was to keep dragging this out rather than adding another point notice how the end points the knobbly bits here are getting larger they're stretching it's stretching the whole mesh okay which isn't exactly ideal it's not how not realistic and not what I want okay so we're going to fix that now we have a different spline actor so I want to do is I'm going to simply just right click and duplicate what we've just done pipe spline fixed so you can see the difference later so opening up their new duplicated one and the way it's going to work this time is rather than getting a location that spline point we're gonna work out how far long on the spline we are and we're going to set a new spry mesh every certain distance okay so we get a distance along the spline point so we've got a few things we need to do here first of all we need to work out how many sections we need okay and the way we can do that is by setting up the for loop here a bit differently so rather than getting the number of spline points here I want to get the length so let's take away that and just get the length and you see it gets blind length and that spits out just a flow of how long natural supplying itself is I then want to divide this by the certain number of this section length so I want them do is going to store that in a variable so go down to your verbal list click the plus verbal and type in section length oh it's miss poet there we go this would be a float and its default value will be whatever the sizes of your mesh and to find that out you can either hover over it and you see a proximate size 100 by 23 by 24 in this case or we can open it up in your stay in the top left hand corner as well 100 by 23 but only for so 100 is its X length which is what I want so the default value for section length will be 100 okay okay okay so now in it got displaying length we need to get the section length you need to divide the spline X by under section length so dragged out by length and topping divide flip by float and tight and drag in your section length this is going to then go straight into the last index here and you get truncate come up truncate by sea knocks off two decimal bit okay cuts it off so now we're going through as many times as we need to based on its length while number point so now we're adding a spline mesh component for every single length and doing the same thing we always have done now the difference will be we want to change these so we're not getting the location or tangents at the spline points now we know when a good get is the location at distance along spline so if I delete the first one here and drag out from spline again it up and get location you'll see get location at distance along spline so drag that in and drag in return value like so and we'll swap these all well before their counterparts so get tangent at distance and delete these copy days and drag them to their pins okay so now for the distance part the distance part is going to be our section length times by the index we'll count'em so section length is PI D 400 so we're gonna multiply int by float hook that up to there and then plug that into the distance and I'm gonna do the exactly the same again it's pond one like so okay so that works because I'm getting section length and multiply it by however far along this line are going so the for loop is going along the line so at point zero right the start of it it's making a spline mesh component saying it's forward actually saying it Center collision and setting a star end to be where in this case zero times bisection length which is zero which is correct is that start get a location a tangent Y that start and get the next point along which is a hundred along because I'm doing a hundred times one this time zero plus one it's 1 times 100 is 100 so that would get me a distance on the spline anyone goes for the loop again this one will be one so special name at 1 by 100 a section in fact 2 by 100 and so on and so forth so this is the first part and you can see it works a little bit differently it's not done yet but we'll see where it's at now so if I drag this in I can move my spline along and you can see it spawning pieces ok so the next problem you can see already happening is it's still stretching and that's because the tangent with the red line you see you can actually see it growing as I move it along the tangent moves with it which is frustrating so I don't want it to move so what we're going to do is going to fix and clamp the tangent so that's the next bit so when we've got tangent been discussed at the end here if this is long spline dragged out of the vector and do clamp vector size and drag that to your tangent and the max for this will be the section length so drag that in section length copy that and put at the end as well and hook it up to the end tangent now oh now if I spawn him in I shouldn't get any stretching which is brilliant which makes it look more like a realistic pipe okay and I can make new points make it curve however exactly I want it to do okay and there you go so there's one last thing we're going to do and this is the last thing for sure if I was to drag in our pipeline and if I then scaled this thing you can see it grow massively even though what I'm doing is scaling it like so so if I want to make the pipe thicker you can see it doing it a bit broken a bit weird so if I delete that so I'll show you again with a bit clearer so make the pipe thicker or later the mesh thicker you can see it's just growing it I want to keep it in proportion so still so if I multiply it by 4.5 which I have here I want the distance between each pipe to be 100 times 4.5 okay so I'm gonna fix that now and you fix it right at the start the construction script and what you do is you get section length and choose set and second link will now become section length so you know such I think so you want to multiply flight by float and you want to get the actors character scow VD split this because you want just the X because X is our forward axis so this will get a scallop in the x-axis times it by then 100 and that becomes a new section name so that 4.5 is now becoming 4.5 times 100 which is 450 okay click compile and you can see here it's now a bit more in proportion if I scaled up I can now see I can now add bits to it this short bit on the end where it tacks on a short bit we can also turn that off if you like you simply what you do is very truncated you just take one away like so and that way it won't spawn another piece and two is enough room for another piece okay and that is it that's prime issues I hope you enjoyed this video and I'll see you next time when we do more spline stuff see ya I have one if you do like these videos and you have liked what I've done in the past and want to see what smell else I can do all your support is greatly appreciated on YouTube however I do have a patreon setup as well where you can support me even further money donated by yourself will help me make better videos a better context and more frequently hopefully plus it will help me develop my own projects currently I'm in a project a moment and I'll hopefully be able to share that with you soon if you do just choose to donate and subscribe to us on patreon you do get access to videos to weeks ahead of time plus there are many other rewards available to you too so head on over to www.skinnygainmuscle.com [Music] [Music]
Info
Channel: Ryan Laley
Views: 207,781
Rating: undefined out of 5
Keywords: UE4, Unreal engine, Unreal, Splines, Rotation, Location, Spline points, Beginner, Explained, Easy, Spline Mesh, Tangents, Fixed, Blueprints, Procedural, Pipes, Roads, Wires, Bendy, Bent
Id: eKIiWa19EMI
Channel Id: undefined
Length: 21min 21sec (1281 seconds)
Published: Thu Jun 14 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.