Splines And Spline Meshes | Creating A Road System Using Splines - Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another unwrenching 4 tutorial in today's video i'm going to be going over how to create a spline in which you create a kind of a road system like this so what you can do is just move a spline to create a road like this so this is just one mesh which i have expanded to create this kind of curve it's just one small 3.7 meter by 3.7 meter square now obviously this doesn't have to be a road it can be for anything that you like but for me i've done a road because in a previous video what i did was have an object move along a spline as you can see this car here so if you want to watch that video just so you can have a car going along like this as well i'll leave a link to that description down below and a lot of people asked to be able to create a road system like this so this is what we need going over and creating today so without further ado let me delete this code and i'll show you how i've done it so the first thing we want to do is you want to actually import our road segment or whatever it is that you're going to be using the spine for and again for my example it is a road so i've just created this in blender very very quickly again is a 3.7 by 3.7 meter square grid and if i go into edit mode you'll notice i've also kind of subdivided this up as well you're gonna want to make sure that you do this and this is so that the spline can actually bend inside unreal so the more polygons more faces and vertices you have in here the better it will bend so you'll notice it will be able to kind of curve around like this instead of just having it square each time but obviously the more you have the more demanding it will be as well so it's about finding a good balance and for me 10 by 10 seem to work great obviously do that how you want then just import this into unreal engine as you would normally if you open this up we can go into wireframe and we can see that we have all those different segments there as well it's a little hard to see because of the um sky sphere in the background as well but you can notice it so that's the first thing that you need to do and once we've done that we can actually create our spline bp so i'm going to right click go to blueprint class create an actor and i'm going to name this one rode spline or you can name it spiderbp again whatever makes more sense for you and open that up straight away the first thing we want to do in here is add a component and add a spline and that is all we need to do in the viewport you can rename that to rode if you want which actually i might do again choose whatever you want and i can compile save that and now we're going to go over the construction script and the reason we're doing it in the construction script instead of the event graph is because this will update every single time we actually change the blueprint so every time we want to add a new spline in there it will do this straight away we don't have to begin the game for the road to spawn in so i hope that makes sense and in here we want to do some nice and simple code the first thing we're going to do is come out of this and get a for loop like so not for each loop just a for loop and the reason we're doing this is because we want to actually create the correct amount of robots for the amount of segments which we create inside of our spline so to figure out how many that's going to be we can drag in our spline which created earlier which i need my road out of this we can get number of spline points and a spline point is again when we add it into the level so when we create a new spline point that's basically what this is so when we hold alt to get a new one however this is obviously going to get all of them we do not want to be including the start and end of our spline so the start and end is obviously two so that's a total of two spline points that we want to take off of the total number so drag out the return value and get an integer minus an integer and we want to minus two so now we've got the total number of spine points excluding the beginning and end and that will go into the last index of the for loop so first index is going to be zero so the total amount of times it will go through this for loop is the amount of spy points we have excluding the start and end point hope that all makes sense again now out of the loop body we're going to add spline mesh component which is something we didn't do last time and this is actually going to add in obviously a mesh which will be our road again whatever it is for you so we now have something visual on this as well if we keep that selected we want to change a few things in here so obviously the most important one is the static mesh we want to actually add something onto here so for me that's going to be my road segment but again choose whatever you want to do you can change the material in here as well if you wanted but i'm not going to bother then the only other thing we need to change in here is the forward axis now i'm going to leave mine as x as that is good for me but this will also be different depending on what mesh you're using so if i compile save and close this i'm going to open up my road segment for me it's going to be x because if you notice in the bottom left down here the forward facing direction for my road is actually on the x-axis so that's the direction i want it to go if it's this way for you you'll notice down here that it's obviously y or if it's going up and down that is obviously z so just change the forward axe here for whatever the forward axis actually is for your mesh so i hope that makes sense so close that and go back to our blueprint now we're adding in the component but we need to tell it where we're adding it so we'll drag out the return value and set start and end nice and simply like this now we also need to figure out the start and end positions just before we do that we're going to drag out the hotel value again and attach component to component connecting that into there the parent for this is just going to be the default scene root of the current blueprint we are in so it's essentially attaching it to the current blueprint so we'll compile and save we're very close to being done again we just need to figure out the start and end positions of our spline and that is why we've got the for loop here with the number of spline points so i'm going to drag in our spline which again for me i named rode out of this we're going to get location and tangent at spline point because again you'll notice we need the start position which is basically location and the tangent again it will be for each specific spline point for each specific road so this one here we can have the index when the for loop go into the point index of that and this is going to be the start position so i'm going to select it press the three dots and just right in here starting position just so we know and then we're going to duplicate this again put the target into there and name this one to be ending position and that's what this one's going to be now we can't just put the index into there because that's obviously going to give us the same thing instead we're going to get an integer plus an integer and connect that in there leaving it as 1. so if we were to add one to the index that's going to be the end position and tangent and just leaving it as it is will be the start so that is perfect we now have the start and end locations and tangents so we can just connect those straight into there start position start tangent end position and tangent like so so that should now be it working perfectly for us so in compile and save that and like i say this should now work perfectly so we should be able to now have our own spine system for me it is a road so if we to minimize this let's drag in our road spline and you'll notice that we now have our actual spline mesh or road mesh story on here if you were to select the end of the spine here hold down left alt and drag out you'll notice it's now as we move our spine it's giving us a new road mesh if i to drag this out again move it left you'll notice it is now curving it nicely instead of just creating a new square to the side it's actually creating a nice curve and that is again because of the subdivisions that we added in inside of blender so this is great we now have it working perfectly we can create new meshes in which we can also curve it to how we want and how we see fit like this so what i'm going to do is i'm just going to create another loop like i did at the start of the video well not really a loop i suppose but just another kind of road system like this just to show it working how we want and another easy tool is up at the top right here you can change between the world and local which is nice like this so you notice this isn't exactly straight however i cycle between it it now is so you can obviously change that and that's good for when you're changing the rotation so if i change it like that it's now a little bit better but if it was like this it's not as good so obviously it just changes about so use it how you see fit now obviously i'm doing this very quickly so it doesn't look amazing you'll also be able to make it look a lot nicer for you well i'm just trying to get in a few straight pieces and a few curves just to show it all off working how we want so what i've done here is i've created a nice and very simple looping system for our road so we now have a nice road going around kind of looks a bit like a race track obviously very small so again that's just how quick and simple it is to create a nice road system like this and again if you watch my previous video which again i'll leave a link to in the description down below what you can do is add a car which will just drive around here automatically now i've already got that set up so i'm going to put that in just to show you it working so if this looks slightly different don't worry it's because it is um it unreal just crashed as i tried to change this up so i've just remade it very quickly uh but all i had to do was replace the spline on the road all the code was still there but let's have a look at this working with the car driving along as well so notice it's going quite quickly this time that's just because i've still got it set to take 15 seconds around the whole thing but it's a much larger map this time but as you can see this does work perfectly so i think that'll be it for this video as we've done if we want to do what we've done is in this video we've actually set it up so we can actually create a visual spline going around so in this example is a road system and again in the previous video we set up creating a car driving along this road link in the description down below but today what we did was we created the system for actually creating a visual spline mesh so as we increase the spline and make it bigger we can place a mesh on there in my example it's a road we can do pipes fences paths really anything you want where you'd want to maybe create a big thing like walls as well so something quite long but also curving this would be the perfect system for you so thanks so much for watching i hope you enjoyed and i hope you found it helpful and if you did make sure to like and subscribe down below so thanks much for watching and i'll see you in the next one [Music]
Info
Channel: Matt Aspland
Views: 59,794
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, blender, ue5, unreal engine 5, road, spline, system, mesh, meshes, splines, spline mesh, curved, curve, dynamic, wall, fence, pipe, example, ue4 spline mesh, mesh spline, spline meshes, along, add, procedurally, procedural, car, ai, npc, path, object, ue4 object follow spline, follow, ue4 spline, how to use, use, make, create, spline path, automatically, automatic, moving an object, along a, roads
Id: RLc20gcc804
Channel Id: undefined
Length: 10min 32sec (632 seconds)
Published: Sun Mar 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.