UE4 Tutorial - Change Materials in Blueprints

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there everybody so in this one we're going to be talking about changing the materials of other objects and i'm going to show you how to do that with the trigger so if you watch right here i can go through this awesome sci-fi door walk up to the sphere and as soon as i hit it look you can see everything in my level has turned to gold so you might be asking how could i do this how can i make a collision change the material on another object i'm going to show you right now so on the gold sphere blueprint you can see i have right here i'm going to open up its blueprint and drag it on over i'm going to explain what's going on so this blueprint comprises of a sphere which is a static mesh it's got a particle system just to make a little fancy and it's got a sphere collider so if you go to components you'd come down you would see collision arguments type collision and a sphere collision okay so the event graph that sphere collider again you can add an event for on overlap when the player my character who's uh my character is just a type of character which is a type of pawn if the thing that overlaps that sphere is of the type of character that i am i go through every actor in the world get all actors of class and the type of class i'm looking for is actor and this is kind of like the parent class almost everything that's placeable in unreal so this kind of like gets everything it's kind of not very efficient but it works for our needs and then for all the things it finds what it does is it goes for each one of those things and each one of those things so this has got a giant list measures a hundred things it takes one at a time so the first thing second thing third thing so imagine we're on the first thing it takes that and gets the component of that actor because actors can be made of multiple components kind of like this blueprint is and it looks for if any of those components are static mesh components and if it does have a static mesh component for let's say that the object has multiple static mesh components on it for each one of those we then loop through okay so at this point we have an object made of multiple static meshes or one for how many static meshes that it has we then take that static mesh component and we get the number of materials that are assigned to it because a static mesh can have more than one material multiple mat ids so we just want to confirm that we get all the materials if we want to make sure everything changes so i can use get number of materials and then for each one of those materials i do a for loop and you might be asking why do i have this negative one here because um if this returned two um imagine there was two materials on an object this would be um it would go zero and then there'd be two here so go zero one two which is actually three so this is like a little trick with arrays so we just do minus one so that we do like one two so zero one that's two and then we use a set material node and we plug that into this element which again is the static mesh element and the target is again that static mesh component okay and then we're plugging in a material and i have this thing called my gold material all right am i asking what what's my gold material where'd you get that from well if we go to event begin play you can see right here i have a node called create dynamic material instance which allows us just to be a little more a little more control over making a material kind of like in run time and we could actually change parameters and things like that but here you can see i just had made a material which you can make yourself i happen to be using a material instance it shouldn't matter you can use just this standard material anything you make and then off of that i just set it to a variable so off these return pins you can click on this and it should just say promote to variable and then that'll create this and i named it okay and that's how we're getting um what you saw when we go up and we change everything once i walk into it now i might be asking what if i don't want to change everything because like you can see it broke the sky like it's just not super great so i'm going to show you how to do that now let's close this temporarily and what i want to show you is this idea of tags so i have a mesh over here and i'm gonna close this little error and what you can see is when we click on any object this just happens to be a static mesh actor but again we're at the actor level if i scroll down actually i'm going to do something we're going to search in its details for tag and i want to show you something there's two different tags here component tag and tags actor tags so the thing you're going to be looking for is actor tags component tags is kind of like a way to separate if like let's say you had a blueprint that had two static meshes in it and you were doing like a get all static mesh components like you could tag some and then like other ones you could tag and you could separate it we won't go into that the thing you're looking for is tags under actor tags okay and if you can see on this one over here when i click on it i actually added just a little string just a word it's called change to gold so i'm gonna copy that text and on this one over here what i'm gonna do is i'm gonna click this little plus okay which is what you would do and you're gonna just type in whatever you want whatever words but i just happen to type in change to gold okay and i'm gonna go back to my blueprint over here my gold sphere open it back up and this time the only difference i'm going to do before we checked the overlap matrix the character got all the actors for each one of those actors we get this if it has a static mesh component what we're going to do is we're going to get every static mesh but this time we're going to do a check so i'm going to come off the loop body for every mesh and if if this mesh right here right this actor has the tag and then again you would just paste in right here in this tag you would type in what that is if it has this tag then i want you to execute if not do nothing so all that means is when we go to play hit play you'll see now coming to my level open the door over here run in the sphere you see nothing really changed but now those two cubes have only changed so you could selectively add a tag to different meshes in your level to have them change their material once you collided with them so hopefully this gives you an idea of how to handle doing some material changing uh especially based on collision inside of unreal engine so again if you like this um just add a like to the video and again thanks to uh chris games for pointing out that we should made a video for it and i will see you guys in the next one cheers
Info
Channel: Polygon University
Views: 2,097
Rating: 4.8730159 out of 5
Keywords: ue4 material changing, ue4 materials, ue4 material blueprint, ue4 tutorial, ue4 material tutorial
Id: sC2_g3p6rx0
Channel Id: undefined
Length: 6min 52sec (412 seconds)
Published: Mon Feb 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.