 Hello, I know it's not being a lot of content being released lately here in the channel That's because I'm working on the next video for the let's make a platform series is about pre-production and game design So it's taking it's taking longer than I thought or intended to But just so we don't enter in a yacht us here in the channel. Let's make a quick video about how we can make selectable objects With this system, we will be able to make exclusive selections meaning that once you select an object the other the previous object will be Deselected and also how you can use using the same system you can create Inclusive selections meaning that you can select an object and keep selecting objects as you want to so without further those Let's get to the tutorial, right? The first thing that we are going to do here is to use an error 2d Let's rename it to selection error 2d And the reason for that is that error 2d's have a very interesting virtual method that we can use to detect when there is a Input from mouse inside of the collision shapes. So let's create a new script. I will use a building script here and The first thing that we are going to do is to create a signal To communicate when this area got selected. So let's say select the selection to go it pass It's current collection state. So selection Next we are going to export a variable to tell if this error 2d is exclusive So that it's kind of like a flag. We can toggle this on or off based on our needs So let's say that by default it is exclusive and then we're going to export another variable That's going to be the selection Action This is the action that we are going to use to detect whether we should select or not this error based on inputs so for instance, I have here in my project project settings a Input action that's called select that is the left button of the mouse so I'm going to use that select for my implementation and Also, we are going to have a variable that communicates the current state of the selection of this object of this error 2d So by default it will start this selected And we are going to encapsulate this variable into a set selected method because we are going to execute some procedures before we actually just In the meantime before changing the selection because for instance, we are going to emit the signal When the selection change when these selections take change So let's implement this set selected method Selected it receives a selection. Okay set get the first thing that we are going to do is to check if the selection is true because if this selection is true we need to Make to check if this object is exclusive or not so that we can deselect all other object and make only this one selected Right, so we are going to make a method that's called make exclusive. Just create it down here And for now, let's just leave it blank We are going to include these objects the selected objects into a selected group node group because this will make easier for us to deselect all other objects If this is an exclusive selection, so we are going to add that to group selected otherwise We are going to remove it from the group. Only then we are going to set the selected to the select selection Value that we are going to receive here Here in this make exclusive. We are going to do the following. We are going to make a group call get three dot call Group on this selected group using this set selected method Passing false this will make so that all objects that are in this group will be Deselected if if this one is selected, but actually if it is not selected We are going to return and then we can just make this group call straight Then we're going to remit the signal that the selection still go Passing the selected and to check if the the selection happened or not We are going to use this virtual function called input event note that here. We have two inputs, right? We have the first input. This is a general use input handling for all nodes But the second one this input event with a viewport as the first argument Here's what we use for errors to differ the text if if an event happened inside the collision shapes So this is the one that we want to so what we are going to do here is to check if the event if the event is Action press the action that we use here and if it is We're going to call this method Tugling the selection what this means is that We are going to pass a value that is the opposite of the current value of the current selected state. So set selected It's going to be not selected So if it is selected, it will not be selected and if you not if it's not selected It will be selected right and this should do it for our selection R2D great for the selection R2D And let's save it here All right, so we have the Backbone of our system and how we can use it. So let let me open a player here So the way that we can use this R2D is Selection R2D is by using attaching them to the object that we want to be selected We can add a collision shape to Tell where it should attack inputs that they are going to trigger the selection We can also just duplicate the very collision shape of the player itself and the way that we Use that is by connecting its signal to a method in this In the object that we want to be selected. So using that I'm going to Connect here. I already have one here. So I'm going to copy that Let me just fold everything else. This is a simple player. It has movement, but the thing that we are going to To go on and off based on the selection is the ability to handle inputs here So we are going to to go off the unhandled input callback from this player based on its selection state So we receive the selection state here and we can simply set unhandled input Based on this selection value and also there is a label here That tells if this object is selected or not so we can Tugger its visibility based on this selection value as well. So label Dot visible it's going to be selection Save and let's go back to our levels of exclusive Know that we can to go on and off the exclusive parameter the exclusive flag using the very inspector itself So this is how we control if an error is exclusive So if it is if it should be deselected based on the selection of other area or if it is Inclusive so we can to go off that if we want that every area Can be selected at the same time There has been a small mistake here. This is This is wrong. This should check if it is exclusive. So this is what actually to goes if this object is a Exclusive or inclusive so made a small mistake here back to the test Here we should have inclusive Exclusive and if we change that to false These objects should be Inclusive yeah, so that's it Thank you so much for watching keep developing and to the next time this video was brought to you by my patrons Thank you so much for support