UE5: Making a Cable Tool in Geometry Script // Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right how to create a geometry script blueprint right click blueprint class and now typically you click actor right that's what you usually do but here you can inherit from a class so instead of just a row actor We'll Inherit from dynamic generated mesh Factor right here not this one but that one select BP geoscript cable let me remove the drum and now you have an actor so we place it in the word you put it somewhere and inside of it it's a typical blueprint right here it has construction script but that's not what you want to to do you don't want that by the way geometry script is I think it can run in runtime we'll do some string to verify that um that should be great Advantage for procedural content generated in the game itself by players but the most important thing the most important use case is to kinda have a construction script but run once right properly cached even saved on disk that's also a possibility with geometry script so the first thing we do we will disable tick in detector we don't need ticking and also what may be interesting to you we don't use the construction script at all instead we go to functions click override and on the bottom we have only rebuilt generated mesh and click that and this event basically replaces our construction script in Geometry script actors and one more thing because I forgot at the beginning it's a plugin it's an official plugin it's been developed for a long time so it's stable but nevertheless you have to go to edit plugins and find geometry script right here and enable that to restart the engine okay this allows this exposes this class generated Dynamic mesh actor so now we have on rebuilt generated mesh let's add some super basic pink so first um errors I'm gonna show you the basics of it let's put it here okay here's our actors pivots pivot it's empty so what can we do we can for example here's Target mesh by the way that's the main mesh but we can have many meshes I will show it later so to this mesh we can add and no sorry in order so first geometry script every function related to it resides in a special subcategory and this is where you should go don't search for things you know randomly just visit this and make sure you checked the basic subcategories of it so geometry script and for example you have booleans to you know cut meshes combine meshes you have banking banking textures banking into vertex color material operations of course there are some concept like material ID vertex list but it doesn't matter at the beginning deformations like Bend twist the usual stuff from 3D software poly puff which we'll use probably today um being you know a spline but from segments and what I want is I want to generate a box so first type geometry script at the beginning and then add whatever you want for example geometry script box append box perfect so this is our Target mesh empty by default and we add a box primitive options make okay it's good we don't need these options defaults are fine the transform let's make it close um transfer all right location is irritation zero scale ah not needed because we have Dimension all right steps do I have to provide it let's see and that's basically it I append box should I update the merge somehow probably not refresh accept commit maybe not let's try compile is here so as you can see simple as that simple as as construction script right on rebuild generated mesh by the way the actor itself should have a button to rebuild or maybe they change it or no so now if you want to prevent changes if you want to work on your graph go to Frozen and click that click that and then restore you know when you when you want to update this again if you have some heavy operations enable rebuilt progress so you see a dialogue but for now it's not needed okay so back to our graph here we opened the box without the material now everything's good but I don't want the box so let me delete that for now and in construction script no sorry in viewport I'm gonna add my own spline for now to be a hard-coded spline just for tests a spline here it is and let me just add some few points dragging without so hold alt and just drag the basic you know use case of unrisp lines okay move come on come on okay and uh again [Music] again okay it's a spline some simple line like this okay let's save it I don't like this dungeon tangent or maybe now it's better maybe this okay compile save here it is our basic heart called the supply so now back to the event graph we get our my spline here and let's convert it to something that geometry script can understand so let's start by kilometer screen um line convert spline to polypath or sample spline to transforms so let's try this at the beginning um here's our spline sampling options it's about frequency of you know how many points because supplies let's say continuous it's infinitely detailed right on an abstraction level but we want to convert it to some points to visualize it as boxes for the beginning of course so number of samples 10 uniform distance or you can do error terminatorial tolerance sorry but uniform distance may be fine for the beginning then samples or maybe 30 what okay um into scale sure and then we have frames so for each each such frame let's append the Box a box to this so for you for each transform retrieved on the path append a box dimensions 30 centimeters okay and the transform will be that transform this Frame translate transforms are returned here with x-axis oriented along spine tangent Z okay let's try here we go it was simpler than I anticipated so take a look boxes they not only sample the spline they also rotate as the description promised with x-axis oriented along spline tangent and Z is the up Vector so here we go right beautiful little geometry script now about following the surface there are at least two ways because sure we can take these points and project downwards Trace against the the geometry but then we lose this very nice automatic rotation orientation so I would rather take the original spline subdivide that and then put these points to to the proper positions let's try if it's possible because I'm not so sure this works for sure let's keep it but what if I took the spline [Music] um let's check what's available in the spline itself there's hot points convert spline to polyline convert I would basically like to resample that or to convert it to a polyline resampled as here and then back to spline set spam that may work actually let's try we had it here this is samples plan to transforms which is fine I guess and then I would like to build build a new spline okay so first we do this let me or maybe no I can detach this for each let's make a new spline so again I want to save it to a variable or no so let's make it a function Target mesh would be nice to have converted to function um and this will be an example and project line okay input pin will be the target match okay I sample it to transforms we can by the way expose this as an input no can I do this oh yeah that's nice so number of samples sure let's go back here enter enter 30. fine okay this is my target mesh what do I want I have my transforms okay come on I have my transforms I save them to a local variable that will be called um original line or maybe wait sample original okay and now for every such point I need I need a new array by the way um so let's make a ring or can I ah I can add a local variable it will be line points project also an array of transforms get and first I want to clear it to be sure and now for every Original Point I want to take this transform get the word oh get location transform location [Music] you can just break the spells from there is location [Music] because these are transforms in the local space I want to transform them to workspace so [Music] um I want this splines get word transform yes and transform [Music] compost transforms I guess Delta rotation hmm [Music] something like that maybe or should I No it should be okay so I transformed this point towards space and then I want to trace line by Channel visibility Channel start will be this and end will be this Plus some you know tracing lengths so split to variable line nice and then and by default it should be I don't know 10 meters okay so this is our start this is our end and it will happen in the loop so again what does it all do first it will be this part command it basically takes this abstract spline and converted to [Music] um like distinct points so resample the obstruct spline will discrete points okay and then here we will have finger points and project them down to the nearest surface like this and this little thing here means convert the local that is the word face okay press complex I guess hmm and what then for now it should just debug draw or some duration like one second let's see what happens okay it actually draws but just negative Trace then should be this but -1 [Music] so we should first multiply it this thing um multiply and negate ah multiply minus one okay yeah now it goes the right direction as you can see sometimes it collides sometimes it doesn't which is good of course if it doesn't Collide what should happen it should probably stay in place in the future we should add some smoothing mechanism but right now let's just move this line a little to make sure that it collides these points here okay like this all right now it should be fine and by the way we can also play some kind of a box in here so let's go back here um I have a cube somewhere um or maybe I called in the Box huh wait a second so I guess the credit content assets malicious yeah Cube come on what's wrong okay and put it here scale it a little and let's put it somewhere inside like this okay maybe actually 274. is good not so good pivot is really weird or isn't okay [Music] I kinda like it maybe a bit bigger maybe actually okay it's good so back to transform 50 like this okay we have our object so let's go back to it again compile right now it collides so what now each of these points should be converted back to local space and added to spline points good um out hits ah there's multitrace sorry line race oh no oops okay for a duration one second [Music] Trace complex now there's out hit so let's split this oops not uh let's only get what we need which is uh location of the impact point in word space so again we take the splines transform and to inverse transform location so word location back to local and then we added here so and what has actually happened it adds a transform okay so we should take this transform and just adjust the location so again this unique and make transform rotation stays scale stays and the location is new and we add this phew okay let's add some more order to this blueprint so this thing it actually becomes very long I don't like such BPS where simple stuff takes a lot of space okay comment Grace okay in geometry and return the local return the hit point in splines local base okay so it should work it compiles and now after all of this is done I think we should start adding sequence because this is for all points all right so let's do a sequence sequence effects first very simple then clear the array and then again to all this [Music] okay and after this is done we should again draw our boxes right so we take this target mesh and do open box but first for each projected point so for each like this transform is here dimensions 30 centimeters and we're good to go so let's try here they are look at this if you instead took the original points they will be here where the spline was drawn but if you do spline points projected they land properly on the surface and when I move this look what happens they actually project let me disable knob look how fast is geometry script compared to stuff like for example Houdini engine because it doesn't have to actually resend the data so again here we are we move the spline and this is not a construction script this is the geometry script plugin resampling the spline projecting points with line Trace and adding boxes and regenerating the mesh the mesh also casts shadows and so on so I think it's insane when it comes to speed of course we will test it on some bigger stuff but still take a look how smooth it is by the way let's let's see what happens to the hardware itself here we are here are the stats this is my new processor by the way always on top there or something like that right always on top oh wait so again just 10 of the CPU and it's still enough let's check this out hi that house games welcome welcome so this is geometry script in action the reprojecting our spline and adding boxes to the mesh GPU is doing a lot of work yeah but that's because I think I'm running a 120 FPS or something oh actually no just 30 okay also what matters is that the stream is encoded on the GPU so you know I think it is unit whoa what's Edge RH yth m game three milliseconds when I move this the game is bigger yeah seven milliseconds so it takes four milliseconds to update this geometry script on average yeah the GPU is doing the work uh Channel no it's not Constructor script that's the whole point so plugins geometry script here then you create a new blueprint so BP based on the dynamic generated mesh here and then in you skip construction script completely you don't use it rather than that you click on functions override and you override on rebuild the generated mesh and here's our function that does this first it does samples plan to transforms then it does line trace for each transform converts it back to low cosplay space of the spline and then this is the only thing that's geometry script right now it's append box whenever the the points are so again these are the original points and these are the reprojective points and that hostgame says that other uses 100 GPU no matter the scene yeah because it tries to give you the max FP as possible you can limit that in the settings uh Tabby Channel asks if doing this on construction script will cause it to be less performant uh I guess and I wonder if we can try I wonder if we can try because then the append box won't be available [Music] um you know what we could probably make a copy of this uh but one eye is right that this is just the beginning so maybe adding boxes will be fast enough in construction script but what we want to do now is to connect the points back into a spline and generate a tube in construction skip you have to use the old procedural mesh component which isn't very user friendly here we'll try to merge them back into a proper mesh and that's something that you could previously do only in Houdini or by hardcore manual working in procedural mesh component zaha says or that I could use the Spanish component to do it in construction script uh kinda [Music] um but then I would have to rely on the Spanish component for rendering the goal here is to get rid of the spline altogether the spline will be only my guide and the final thing that comes out of geometry script is actual proper well optimized mesh that you can even do remove duplicates or something like that no remove anyway in Geometry script there is a cleanup that you can weld duplicate vertices for example so I think it's well worth trying that uh here okay so exactly right how red house games is glad that we moved on from procedural mesh component it was a good first attempt but programmer only and hardcore okay so there there are the boxes let's skip them for now I'll just make a comment like visualize what I want our final spine points let's make it like yellow or something debug okay so let's reconnect them back um into a proper spline so let's make a new play to add [Music] line company okay Target so [Music] add a new spline and this line adds blind points points are here uh-huh so again uh projected or each for each of those what does it expect actually at Point rather point just position come on fine point make it position on guns rotation okay break transform like this like this dance like that probably I should calculate the tangent somehow but I don't care yet what's input key aha this is in percentage or something um [Music] so input key is from 0 to 1 or rather input key I don't like it what's input key okay whatever let's see what happens and I would like to visualize that new spline how can I actually do it oh it will hang not good because I didn't save oh input King goes from zero to number spline points damn I should have asked and tab you're asking about performance it depends right because one spline is visible in construction scripts a few of them probably also but imagine having let's say procedure generated house in game oh something bad happened here uh at Point and then the spine update after everything is done so uncompleted so input key should be my array index I guess what yeah supplies are really useful right now in unreal because they used to be no very basic but now there's a ton of functions to handle them sorry I pressed Ctrl Z and I just shouldn't I literally just shouldn't do it oh Scott posted on on Discord that he made something like that but in C plus plus before geometry script was a thing it was a massive pain sure massive pain but it looks nice it looks really nice [Music] ah and yours are on on stream okay let's invite people copy Instagram yeah really looking really smooth and kind of doing a good job about Houdini yeah Houdini is a good environment that's true that even if blooping if geometry script gets forward with you know the functionality still Houdini wins when it comes to the environment of let's say debugging your process if you then you can right click on any node and let's say display this immediately or visualize this as color I hope that's either something that epic thinks about or something that one once we can do you know or I can do step by step like a utility library right like right now I have these boxes that visualize my path I would like this to be a built-in functionality because this is something you can just expect from Houdini that visualize my points you get kind of this so I hope either they get there or we get there okay I update the new spline and now it seems to work yeah it's visible take a look it's here if I delete this section it's gone and now it's here this new spline but the connections between them are screwed up they're just plenty wrong um so I wonder what's wrong transform is zero yeah type is curve let's do linear better but still wrong each of is connected to another uh arrived and get this done again update spline sure can you see it maybe I have to go to wiper mode yeah so every point is connected to every point do you know how to do it how to make you know zero connected to one one to two and so on by the way here something wrong happened this point is completely gone somewhere but the cube is not here so I don't know what's that point actually so again for each projected point the location goes to position rotation to rotation scale to scale input key is our index or maybe input key should be the previous point or no but it's really matter it will be just off by one but still everyone is connected to every other thing hmm and spline point at index maybe like that let's try instead of this we'll do this position comes here index will be array index card space vocal let's try now seems to be better yeah it is better actually okay so I shouldn't at the point that's right nice adds blind point add index all right and updating only once once it's completed because I don't need to update you know to ring the loop right so here I'd call that whoops sorry unpack it come on uh command make a new spline and the product components oh yeah that's how show it on personal projects on Discord if you can okay so we have a new spline I just shouldn't it shouldn't be closed it should be open closed set closed loop pause let's add it and okay uh now it's okay I guess but what's that connection what the hell it goes back to some weird points uh sorry again let's disable that can you just okay yeah here we go no extra points and then this okay it's here by the circle and there's a point added at zero why and this I don't know what they are to be honest I know what I should do when we project when we project I should remove the ones that weren't a blocking hit or here it will of course make the number of points potentially different but still break no branch and only if this is true only then add a point oops you know so that point that float in the air won't be added so blocking hit hmm but still something is wrong with these two what are they even I don't know okay I have no idea so add the spine component I have a bit has some points by default uh yeah maybe unreal just add something uh remove points or clear points and then do this that's stupid so by default Android adds two points the display just to have something to show okay so now it works we clear the points for each projected point we add a new one like this disable the closed loop and update spline only once at the end okay look it's smooth and it works it's smooth and it works so it means that we can actually now try to make geometry out of it so instead of adding boxes let's try adding circles and probably the rotation I don't know if it's correct we'll see we will see to make a new one let's not visualize them like that yet or you know what I could actually pack it into a function this collapse the function and it will be visualize points as boxes just like that okay so for now I'm gonna copy this again disable it here okay no boxes and I will put them here out of the new spline so let's take the new spline I should actually save it to a variable to be honest so promote the variable um [Music] let's call this new VAR like line rap project pattern or Sprint Project nine user input oh that helps games thanks for posting on Discord all needs creation all this creates that sounds really cool thanks for sharing so this is all created entirely in engine using Sprout the plugin they're making that is really nice is the plugin upcoming or closed beta thanks for sharing awesome stuff so again someone bringing stuff back to the engine itself foreign ER okay share this as well when you're ready so back here uh I project that it's our new component can I projected okay and now let me visualize that spline project let's see what rotations are this to transforms sampling options the same so 30 samples um all right another sequence foreign distance sure sure and now just display them Target mesh is our Target match okay cool they are here the rotation seems correct yeah it's really good it's really good it follows it's good okay so the rotations were created kinda automatically by unreal and they make sense at least at this level of detail let's add some more let's add 100 cubes great steal fast as you can see very fast let's add the 1000 cubes space compile uh okay it still works he's really bad okay now the processor becomes Kinda hot I can see the fan speaking up but come on it's 1000 cubes along this line okay so we have the cubes and they work fine let's convert them to circles so let's disable that um maybe that's 100 and now for each let's add a circle just as a test we'll collect them later so where's our mesh you know what I should save that mesh so go to the variable because let's call it um nice dynamic fantastic now here my Dynamic mesh I would rename it to something later Maybe okay for each of them to my Dynamic mesh are circle answer or is it a disk okay disk this is good but this will be filled primitive options polygroup mode can I have it without the scale hmm all radius polypov create Circle Puff 3D sounds good and it gives us a poly puff structure radius will be this the transform will be that radius let's say for d for now number of points vertically okay cool what can I do with this poly Puff I create a circle um but can I display a wireframe with this probably no convert poly path to array of vertices curve sweep that's a good idea paint sweep only line sweep the given to the pony line along this way oh wow you're clever thank you so my sweep path will be displayed RF trans 49 first vertices of the open to the path that will be swept along the sweep above great um that's great Target mesh is this mesh by the way let's say because it will explode the Primitive options I didn't characters from I don't care a loop I guess [Music] um okay and this transforms that we have here let's use them as ah I don't need it for don't need to do it in a for Loop okay because I have a pen swipe right along the path so we just create a circle to the mass 2009 thanks for following okay here we go this is our sweep puff so a circle sorry a polyline a circle sweep path let's see what happens oh that works thanks Red House games take a look it's just unnecessarily closed and no it isn't yeah that's what we wanted let's make it smaller clean here we go look at this offense with 49 and now I can move the point as a user user of the tool and it just snaps into just three branches okay can I select the whole actor yeah look how fast it is real time kholini is also fast but you will see this little hits when the geometry is transferred that's really cool okay and of course we can sweep any shape right it can be like real number of points free and will be a triangle here but now we can increase the number of points to let's say 128 and here we go a very dense array now of course we sampled it just to 100 can I apply a material to it I would like to do something like look at mass that material [Music] you can do it here I want Rome to show you you know the Precision of the Geo so let's go back here um let's do three and yeah now you can clearly see this is a very simplistic geometry eight points better 32 points smooth um and now there isn't enough points on the spine itself so let's go back here and do 500 samples it's good so what we miss to have a proper tool is to smooth out certain things based on stretch elasticity and so on and we really miss some detection of collision right to normalize the thing and right now it's based on The Middle we should erase it raise the curve by thickness of thickness so let's go back to radius let's convert it to a variable that will be called uh table radius okay 15 let's make the user editable and now this cable radius thing we should add it to the Curve so sweep offshore but transform make that if transform I guess oops just make transform break location um cable radius divided by two and here it will be of the rainbow [Music] compile yeah now it's correct it exactly lies on the shirt exactly lie on the surface okay here we go let's make it gold or something to make it more visible [Music] here [Music] foreign back here here we go so this whole thing will be uh generating a mesh the mesh of the cable okay we're good look at this just look at the pink Now we move it just works
Info
Channel: Tech Art Aid
Views: 14,819
Rating: undefined out of 5
Keywords: tech art, ue4, ue5, unreal engine, tutorial, procedural, game art, blueprint
Id: DkjZU_fN5QE
Channel Id: undefined
Length: 66min 56sec (4016 seconds)
Published: Mon Nov 07 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.