 Hello there, this is the second part of a video series that me and Nathan from duty quest are making together If you didn't watch the first part yet I highly recommend you to do so because this second video starts from where the first part ended You will really need the knowledge of the first part here Okay, so put the link to the video in the card that is appearing on the screen right now and also in the First comment on the pilot comment. I'll wait a second until you finish watching the first part Okay Finished. Did you know what what a plug-in does? You know how to make a configuration file Okay, so let's get started Here we are where we finished the first part So we already have this setup made and finally we can work in our plug-in So in the ready callback, I will go to the editor interface interface and get the selection Which as we saw returns an editor selection That is a class responsible to handle selections in the editor and it has a signal called selection changed So we will connect this signal to our plug-in so connect selection changed Signal to this plug-in at the on selection Changed method. So let's create this on selection changed method here function on selection changed and whenever the selection changed if we have more than One node selected because this plug-in will handle multiple nodes, right? We'll get the editor interface again. We will get the selection again And we'll get the selected nodes Which returns a list an array of the current selected nodes So we'll see if the size of this array Is greater than one. So we have more than two nodes selected, right? If so, we'll set the process Input to be true so that we can handle a shortcut for instance Otherwise we'll set to false. So we don't handle anything at all And just to make sure that this works from the start from the beginning I will also add this on the ready callback here Let's not forget that the get selection. It's also a method. So add this is here So we go to the editor interface get the selection get the selected nodes and see if the size of this array is greater than one Next let's create an interface a way the user in our case. It can be ourselves We'll be able to enter a name and confirm that this is the name that the node shall take from now on Let's create a new scene here With a control node. So control I'll set the layout of this node to be the full rectangle and I will add a color wrecked node and also make it takes the full rectangle as well, but this will be dark color with a Smaller alpha. So it's transparent, right? We'll also add a line edit node Which is a node that allows you to enter a text and to confirm a text and you see that this Offers a text entered signal which happens whenever the user press enter with this node selected So it can input some text and press enter and this signal will be emitted Let's move this to the center of this note. So I will use layout Center here and I will add a placeholder text telling you to input New name. I will increase the size to fit the name here. I will use center So here we have it now. We can save the scene inside our add-on folder. I will call this renamer Rename scene save it and now we can go back to our add-on script Back to the script in the input Callback, we will check if the f12 keyword is being pressed. So we can use the input class and check if Is key press it and pass the key f12 key If this is true, if we are pre if we press it this key We will create an instance of the interface we created of the node tree that we created I will call this just R and we will load the scene so this and create an instance of it so dot instance and I will go to this scene and get the line edit node And as we saw we have a signal called text entered So let me open the scene and here in the line edit node We have this text entered signal. So we'll connect this to our plugin. Let's go back to the script connect the text Entered signal to this plugin. I will just skip the line here So we have more space for it and we'll connect it at the on text entered Method and we will also pass an extra argument that will be a reference to this node We just created so I will add brackets here at the R Which is this node, right the node that we just created and pass it as an extra argument and After that we can add this node we created So it will be an instance of this scene of the rename scene to our Plugging so we can use the add child and pass this are The the node that we just created the instance of our interface scene Now let's create this method right here Funk and I will copy it and paste it right here And as we can see it passes a string with the new text. So new text And we also Receive an extra argument which will be reference to the interface. So let's call this interface here And now comes the hardest part here. First, we will have to create a list of what's being selected So get interface get enter interface dot get selection dot get Selected nodes just like we did here But we won't check the size and we will sort this using a custom function. So nodes dot sort Custom and we'll create a function in this plugin So we'll pass the cell because the sort custom function the sort custom method receives an object and a Method that will be used to sort the ray. So we'll create a method that will sort by the node index So we'll use this to sort this array here. So let's create this function funk Sort by index and a custom sort method will receive two objects So object a and object b and it will return a boolean which will be easy to sort these nodes The the logic here is that if the index of a Is greater than b dot get index We will return true. So we will actually return the the result of this operation So if a is greater than b will return true if a is smaller than b will return false This is so that we can rename the the nodes based on the order of the hierarchy After that for each node in the nodes array We will set the name to be the new text name and then we will Free the interface. So we'll go to the interface and kill it free And finally we can test our plugin. So let's go to the project project settings in the plugins tab We'll activate this add-on And let's create a test scene here. So I'll add a node and I will add some other nodes as its children duplicate this I will select every node here press f12 And I will name them Just uh test As you can see it doesn't update immediately. But if we switch the tab and switch back We'll have the nodes renamed But as you can see we have the inverted order. So let's go back to the script here And invert this logic here. So if the get index is smaller than the get index of the b object We'll return true. So save it project settings Disactivate activate again And I will select this again press f12 Name this to node Press enter switch the scene switch back and here we have it And this is it as I said in the first part later we'll make a more elaborated and complex Plugin but for this video, that's all. Thank you so much for watching. Keep developing and until the next time