Unreal Engine 4 - Chaos Destruction Basics Pt. 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys smartpoly here welcome back to another video so today i will be continuing my chaos destruction series and in this video we will learn what sleep disable and kill feeds are why they are important and how to make them also at the end of this video i will show you how to cash large-scale destruction simulations so you can have large-scale destruction much like how battlefield 4 had their revolution or massive skyscrapers can be destructible so now if you guys haven't already watched the getting started video and the basics video go ahead and check those out first because there's a lot of important information that you need to know so first of all to review what we learned in our previous video we learned all about anchor fields and fracturing your mesh we talked about various levels of fractures that you can apply to potentially have hundreds of small rigid bodies or fractures and you've probably already noticed when you click play and you shoot your mesh how your frame rate drops when all these rigid bodies are simulating all at once and how still your frame rate is pretty low when everything is already destroyed and all these rigid bodies are simulating so that's where sleep disable and kill fields come into play first of all sleep fields are the first field we will talk about now remember fields are basically a region of space that you can define in a blueprint and sleep fields in particular define a specific box area to put rigid bodies to sleep sleeping rigid bodies can be woken up and continue to simulate by fields and collisions next up we have disable fields disable fields also define a specific region of space to disable rigid bodies in that space disabled rigid bodies are completely removed from the simulation so once removed they can be reactivated only by fields and not by collision fields like the sleep field lastly we have what is called a kill field this type of field can stop simulation when when the center of mass touches them they can no longer be reactivated by collisions or fields and this last option can be useful for when the rigid bodies are no longer visible to the player so for example if the player is really far away from this destructible asset you want to obviously not have it be simulating so let's go ahead and see how this works with blueprints so i have chaos destruction examples here and what i have here is our sleep field our disable field our kill box field so first of all what our sleep field is is basically it's just this little box right here and you see here in the components we have a box and a cube so we have a box collision and a cube which is just a visual representation of it with a purple material applied to it okay and in the components we have two box falloffs and a calling field and then all the blueprint is here in the event graph it's really simple you have an event tick hooked up to apply physics field which is a sleeping threshold because remember this is a sleeping field basically it tells when a rigid body falls into this little box it's going to tell that rigid body if it's within a certain threshold to put that rigid body to sleep okay and i'll show you how to make this here in a second from scratch okay and then we have the disable field which is basically the same thing but this is set to disable so same thing different color obviously to represent sable and the kill box also pretty much the same thing but this is set to kill and there's an extra branch in here which is just seeing if the kill is active okay let's go ahead and create this real quick so in our chaos basics project here um if you haven't created this project from the last tutorial i'll leave a download link to download it in the description below but basically we're going to create a new field and if you remember correctly you have to make sure you have the chaos field system enabled as a plugin and to create a new field we're going to right click and go to physics create a new field system we'll name this sleep field drag it into your scene and right over here you're gonna click blueprint add script this is going to pop up it's going to select field system actor and it will create a sleep field blueprint and it's also created here in your content browser okay so we're going to add a component here a box collision and then we're going to add another component a cube and let's go ahead and actually change our material here on our cube we're going to change it to a transparent material so you can do this by either creating a new material or what i like to do is go to view options make sure you show engine content then you're going to have all these other these basic materials here really anything that's transparent like this color brush mask material you can we can actually use this is good and then we also have to make sure our box collision here is properly scaled okay so we'll just have to scale down the cube here make sure that's locked we can go ahead and scale that to meet the same size as our box collision here and remember the cube here is just really a visual representation for us so later on in your game you'd basically just delete this because it's just visual for us for the artists okay over in the components you're going to add box fall off go ahead and duplicate it again and name this box follow colon then add a component this is going to be a culling field okay and then we can go into our event graph delete all this at event tick get your field system component and apply physics field go ahead and set this to your sleeping threshold which is the sleeping field click enabled drag the event tick into the apply physics field then we're going to get the calling field drag off there set culling field hook that up to the field on the apply physics field you're going to make sure you change this to outside this is very important this is going to specify which region of space you want this to be affected by so for this example we wanted to only be inside this cube we also want to drag off here box falloff cooling and set box falloff hook this up into the colon set the minimum range here to one maximum range to one fall off to none you can go ahead and duplicate the set box fall off paste it right here hook that up to the field and then hook up the box falloff to that and off the magnitude we can go ahead and drag this off promote this to available you want to name this variable compile save that and then we're going to get our box collision drag off that and get world transform hook that up to the transforms of each box fall off here and that's pretty much it you're done in our sleep field you also want to go to your threshold right here and make sure it's instance edible and expose on spawn okay compile save that so back in the sleep field blueprint select the cube scroll down to collision presets set this to no collision okay so what we basically did is we're applying a physics field a sleeping threshold to this specific area defined by this box region and how it works is we'll go ahead and go back to our scene here we're going to scale this up here something like so okay and set it up like that let me bring this down just a little bit uh one more thing i want to add is our anchor blueprint or anchor field that we made in the last tutorial we want to do the same thing that we just did so go ahead and open it up make sure that the box collision and the cube collision match up so you might have to scale your cube to match it up to the box collision in the construction script you want to make sure you're using the box collision for the get world transform so i think we use the q collision prior in the last tutorial but you want to change that to box collision and then cube right here you want to set that also to no collision for some reason i had it set up weird in my previous tutorial don't let this confuse you because really the cube is just again a visual representation uh you're really only using the box collision as the defined region of space that you want to use all right now in our scene here what we can go ahead and do before we hit play set our threshold here to a value of say five hundred thousand so basically uh this threshold is this uh variable that we've set here basically what it does is when a rigid body falls once it travels into this box and reaches a certain velocity measured in centimeters per second it will go to sleep okay so we hit play okay so real quick i had this little bug where when i hit play it automatically everything just fell to the ground and destroyed so i deleted my sleep field i readjusted my anchors here and kind of moved things around a little bit just little bugs here and there uh when working with chaos since it is in beta okay i'm going to go ahead and re-drag our sleep field back in here and scale it up okay and so before we hit play we just want to set the threshold 500 000 hit play then if we hit that part you're going to see okay first of all it's colliding with each other and kind of flinging those pieces around which i'll have to discuss here in a second but what i want to talk about initially here as you can see partially you can see some of the pieces here are completely still and that's basically our sleep field in action you can still see some jittering here and there uh when these little rigid bodies are colliding with each other so basically sleep field puts the rigid bodies to sleep but they can be woken up and continue to simulate by other fields and collisions so for example a collision would be like if i were to collide with this you can see it's working again it's really buggy still and basically the reason why you can see a lot of glitching with this is because right now at least the threshold sets up 500 000 so they're creating these little chain reactions where one rigid body is hitting another rigid body and it's just continuing to like create this like chain reaction of jitter in it okay so i'll play it again and show you here a little bit how things are working okay so again lots of pieces flying all over the place i'm gonna have to play with that a little bit but let's go ahead and move on to the next field which is the disable field so we can actually use the same sleep field that we have here and changes to disable threshold so if we compile and save that and hit play go ahead and shoot this and you can see it falls instantly and it's instantly disabled okay so you can see i walk through these meshes here and there's no collision basically like i said before disable fields um can only be reactivated by fields and not collisions so that means that i can't collide with it once it's gone through the disabled field part of this you can see it fall like that maybe if we can get part of that simulate you can see it automatically falls and just stops like that so we can change the threshold here and bring it down so bring the value down will allow it to have a lower velocity so when the pieces hit the ground it'll have more time to spread out and collide with each other so hit play you can see parts of it still kind of spread out just like that and they had more time to spread out before uh disabling okay and also we can change this to kill so if we go back into our sleep field and change this to a kill field and so if we hit play issue right there just kills the simulation so basically a kill field can no longer be reactivated by collisions or fields so i can run through this freely and if i were to shoot any sort of field try to apply a feel to it it's not going to reactivate any simulation so that's pretty much all the different fields here so before we move on i just real quick want to show you guys the example here in the chaos destruction demo where they use here this disable plane basically you can create instead of a disabled box a plane which is a little bit different um but it's basically just a plane plane fall off plane calling and culling field you're just setting the plane fall off it's pretty much the same as a box the only difference is that a plane is less expensive it applies it to the entire level it's a infinite plane okay so if i just play from here i can show you this gonna see these explosions are gonna fracture and explode part of this building you see all these little rigid bodies fall onto the disable field and you can see our frame rate dropped when it was all being destroyed but obviously now it's a little bit more cleaner uh because of these rigid bodies here falling into that disabled field okay so hopefully guys could see the importance of sleep uh disable and kill fields by now and we're gonna move on to the next topic which is caching so basically what caching does is it allows you to do what we just did in that simulation but without losing uh basically any frame rate so i can simulate this and you'll see it's going to play the same simulation but this is all cached so you can see we're not losing any frame rate here because this is playing back the simulation that's been pre-simulated basically how epic achieved a large-scale destruction in their demo video because obviously if you're gonna have you know a massive skyscraper or a lot of buildings being destroyed my current computers can't really handle that many rigid bodies at once especially you know if you don't have like the best pc so you're gonna have to use caching to basically save a simulation and replay it whenever you need to replay it alright so i'm going to show you guys basically how caching works and what i've actually found out is that caching in 4.25 is kind of broken at the moment so i'm actually in the 4.23 branch of chaos here in the chaos destruction demo really any project that's version 4.23 caching will work and then i also have this roman statue here for mega scans imported here and i've already scaled it up pretty large here i'm going to go ahead and just fracture this here real quick so click so make a new geometry collection okay and then so we should have a few levels here okay and then in our little uh damage threshold we'll add a couple here so we'll go ahead and go browse to acid and set masses density crank this up okay you see the structure the statue just crumbles like that how we can go ahead and do is actually set this up to cache and save the simulation here basically under the caching tab under the caching parameters set this to record and then you can either play or simulate doesn't matter okay and hit stop and then if you click back on here you're gonna see valid uh cache valid for playback and record so it'll create automatically this target cache and in for some reason in 4.25 it wouldn't create this file so for some reason it's broken anyways in here we can go ahead and set this to play and then we're gonna set this from object type to dynamic to kinematic okay so if we hit play now it's gonna simulate the exact same way that we had it before sophia simulate again it's going to simulate the same exact way alright so if we actually rotate it i'm gonna see it's gonna go back to that same position and play exactly how it was before so we're just playing back the geometry collection cache that we've recorded and you can also set this up in sequencer uh to playback depending on you know a gameplay event or something like that so yeah that's pretty much all i wanted what i wanted to show and obviously you know you could make the statue have more fractures and more tinier little pieces you can really get the most value out of caching you know a large-scale destruction but yeah that's pretty much going to be it for this video i hope you guys enjoy the video if you like this video make sure you leave a thumbs up and i'll see you guys in the next one
Info
Channel: Smart Poly
Views: 13,615
Rating: undefined out of 5
Keywords:
Id: LRD1qoC5Q6A
Channel Id: undefined
Length: 19min 14sec (1154 seconds)
Published: Thu Jul 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.