 Hey welcome back to Game Dev Academy, I'm Shane. Please sign the register by leaving any comment down below the video and I will be popping your name up on screen in the next video just like I'm doing with these names right now. In the last video we didn't do too much, it was a nice simple one where we just got a new one to spoil when the old one died. But in this one it's going to be a little bit more involved, we're going to make it so that we can have different coloured blocks by making use of a dynamic material instance and we're also going to make it so that we can set different points values to each of the blocks that we've placed as well, which we can use for counting up points later. So let's get ready to jump into that after I tell you about this video sponsor. Today's video sponsor is Out of the Box plugins. They provide modular plugins for Unreal Engine from simple quality of life changes to complex systems to speed up your development process. They provide clean and easy to use blueprints to take away some of the pain of programming. Use the link below to find out more about what they have to offer. In this step what we're going to be doing is setting up our block blueprints so that we can have different coloured blocks and have the blocks with different scores all coming from the same blueprint actor. So that's what we'll set up now but first of all I just want to do a bit of tidying up in the ball, a couple of jobs that we need to do. So the first thing I'm going to do is find my begin play section here which is where I'm getting my player and I want to get the game mode as well because we're going to need to make it so that we're getting scores from the blocks when they're destroyed and we're going to need to store the scores in the game mode and then get that printed to screen. So we need to make sure that we've got access to the game mode in here and so the way I'll do that is I'm just going to right click here and do get game mode, oh get game mode. There we go and out of the return value of this I'm just going to cast to my game mode. So there it is, BO game mode for breakout and then what I want to do is just get that so that it follows from this begin play because as soon as we begin the game I want to make sure that we've got access to that. So there we go let's just line that up a little bit. Lovely and what I want to do is make sure that I've got access to this as a variable within this blueprint so I'm going to as game mode drag out of here and then just promote to variable and that's going to set this as a new variable and we're going to call it game mode and then we've got access to our game mode which is good and of course it's always a good idea to comment so let's add a comment to that and it's just going to be get game mode so we know what that's doing. The last bit that we need to do on this before we're finished is just compile and save and then we're done in this blueprint for now where we need to be working now is in the block blueprint so we'll move back here to find it there's the BP underscore block so let's get that open and now we can add some features to the block. So all we have really on this happening so far is that when the ball hits it then it's going to destroy which is fine but we need to get a few other bits of functionality in there as well and we're going to do that through the use of the construction script. Construction scripts basically these fire every time a block is spawned so we can have control of that at the actual spawn of a blueprint rather than at the beginning so in the regular blueprint in the event graph we can do things on begin play but we want this to happen whenever it spawns so into the construction script that here's the little purple thing to get started so what we're going to do to get the blocks with different colors is we're going to create a dynamic material instance and that will just allow us to when we drop a block in the level we can then change the color of it and it'll all be based on the same blueprint so that's really cool so what we'll do is just click on block up here there we go and then we're going to just from our construction script we'll drag out of here and we're going to do a dynamic material instance so there it is create dynamic material instance for the block so we will select that and what we need to do is set the source material for this so what we're going to be creating dynamic instances of it's going to be the m underscore basic for now which is just the one material that we've created so that that makes sense now we need a new variable so I'm just going to click on the plus symbol here we're going to call this block color get my capitals in the right place block color and what I'm going to do with this is I'm going to click on this little eye here so you can see this is the variable is not public and will not be editable on the instance of this blueprint that's telling us that it's not doing what we want it to do let's click that and it'll change the variable is public but missing tool tip I don't think that's supposed to happen I think there's a little bug in Unreal Engine and so what this means I'll explain it for you is that now we've clicked on the add this makes this this variable public and so when we're in the level whenever we create an instance of this blueprint we can change this variable which will be very useful to us for creating our dynamic material instance for each of the different blocks the type of variable is not right for this because at the moment it's a Boolean and we want to change the variable type to linear color so it's not in the kind of standard one so I'm just going to start typing it linear color there it is and then we know that that will be a color which is what we want whilst we're not going to be doing anything with the points yet we are going to take this opportunity to set it up so we're going to add another variable as well I'm going to call this one points so this is what each one of the blocks is going to be worth this needs to be public as well so that we can change that from within the level and we're going to change the variable type to float integer probably works as well but I'm going with float so at this stage I'm just going to compile and save just so I know where I am and it gives me access to some of my variables here as well so you can see now I can change things here if I want to or if I can see what I'm doing I've got a color there as well but we're not quite done with this construction script yet so out of the return value here we need a set vector parameter and you can see that we're now going to be setting the color using this it tells you in the tooltip there's the target is the material instance dynamic we've got a dynamic material instance here I don't know if change the ordering of the words but that's going to allow us to set that and what we need to do is just get the block color so let's get it and we're going to connect it to the value so that's what's going to be setting the color of our dynamic material instance and just so that we get the right starting color I'm going to set the default color of the block material to white and it will at least match up with what we've got already I also just want to give a name to this parameter under parameter name I'm just going to call it color I should do nicely and that should do it for us for now so we're going to compile and save this and see whether or not it's having the desired functionality in our level so let's go back to level one you can see I've already got my my rows of blocks set up so let's get a little bit close to these so I can see them lovely and I'm just going to select I'll select them a row at a time so let's get this top row here and the color for these they're kind of furthest away so I'm probably just going to set these to red you can see now that I've got them selected these parameters that I've just added have become available so I can set the color of these blocks hopefully so let's set these ones to red hey it's working whoo so we'll set those to red bonza and let's say that these are going to be worth 100 points by some big points right there okay so keeping sort of in line with the original I think the next row I'm going to have as being like an orange color so let's just find something that looks kind of orange that's nice and orangey I think so click okay on that and the points for these let's have we're going to set these at 50 that is a good points number I think then we're going to work our way down to the next row I think you can see where I'm going with this now you can probably work out the rest for yourself but I shall put you some video just to be helpful according to my little guide that I've got on screen as well for the breakout colors I think this is going to be like a light of orange so let's just or maybe going towards yellow something just a yellowy orange let's let's go with that and the next set of points we're going to set to 25 we'll halve it again and then we're going to go to the next to last row right here we'll give these 10 points each and the color we'll probably just keep working our way around this color wheel I think is a good way to go so you'll need to be hitting the green spectrum a little bit and then we'll just go to this nearest row of the blocks and five points these are rubbish blocks we don't want any more than five points for these because they're not that good they're just the closest ones and we'll have a nice greeny green color hey that looks beautiful it's like a rainbow okay let's have a little look see how that's looking in game oh that is looking pretty there we go so we now have different color blocks that we can add in level and we can also assign different points to them which we can add up we're not actually counting the points up yet we're not doing anything with them but it does mean that we will be able to going forward so before we can actually do anything with the score we're going to need a bit of a UI to the game so we're going to need to count how many lives or balls we've got left and we're also going to need to put the score on screen so the next step is going to be about setting up that UI and getting it to display so i hope to see you for that one i believe that quality education should be available to everybody and for that reason all of the classes at game dev academy are completely free and we're supported by our very generous school governors over at patreon if you'd like to become a game dev academy governor and support our work as well as helping us to steer the channel in the right direction then use the link in the description to be taken to the patreon page