 Howdy, guys. All right. So in this video, what I want to do is show you guys a early preview package for unity Which is the Python for unity package and I'm really excited about this because it opens up the opportunity for me At least to hook up Houdini directly to unity without having to use the Houdini engine and While I love the Houdini engine. Don't get me wrong. I think it's super cool When you start working on, you know, larger pipelines and stuff like that. You really want to have a little bit more control And this is what, you know, Python for unity is really going to open up for us And so in this video what we're going to do is we are going to walk through installing Python onto our our PC I'm going to be doing it on Windows and then we're going to learn how we get the Unityful or Python for unity package Installed into unity because it's not in the package manager and then we're going to learn how to start to work with Python inside of unity in this case what we're going to do is we're going to create a very basic custom inspector editor here and We're going to run some Python script with it. So we write just a really basic set of Python for unity and then we use this button to run it and what happens Let me actually do that one more time there is It's going to print out all the names of all the objects in the current scene all using Python in a little bit of C-Sharp too So super cool stuff. Hope you guys are excited. Let's get started All right, so the first step in getting a Python for unity all set up is to actually install Python now You might already have this installed on your machine, but take note that Python for unity currently does not work with Python 3 So if you go to this particular link right here, you can find the documentation for Python for unity 2.0 0.1 And it specifically states that it does not work for Python 3 So you might have to install Python 2.7.5 or later for it to work All right, and so if you just click that link It'll take you to this particular page where you can go and download the installer and what I'm going to do is download the Windows 64 bit installer All right, so we're just going to click that link and download it and again I am working on Windows only here. So you'll have to follow the Instructions for Mac if you are using a Mac here. All right, so once it's downloaded, which happens really fast because it's a tiny executable I am just going to double-click it here and I am going to then walk through all of the setup options here for you guys And so I'm just going to install it for all users. This is my laptop. I'm pretty much the only user I'm going to install it into the default location. So see Python 2.7 hit next and Currently I did an uninstall my previous installation, but there must have been some stuff left over so we're just going to say yes and We're going to go into the advanced and we don't need to do any of that stuff there So everything is looking good. I'm going to hit next and let this install Doesn't take very long Now one thing the documentation while that is installing says that You should actually check to make sure the Option to add the path is on now in the installer that I just downloaded There was no option for that that I saw at least so we'll have to make sure that we go into our environment variables and set that up Manually which isn't all that difficult at all. So let's see how our installation is coming here almost done So I'll be right back once this is finished All right, so that finished up. I'm just going to hit the finish button now I have tried this actually without actually adding it to the path and it worked just fine I'm just going to go and show you guys how to do that really quick. So let's go to our environment variables. So I just opened up the Windows option here by hitting the Windows key on the keyboard and I'm going to go and edit the system variables and We're going to hit the environment variables button And then we want to go and find the path system variable and we want to edit that and all we need to do really is just Add a new option here and that's going to be c colon Backslash and then Python to 7 I believe it is If we go to our C drive here really quick, we can always go and find out It'll be in our Python 2.7 right there So what we're doing is we're telling Windows where the Python executable is so we don't have to type it manually So we don't have to type this whole path All right, so that looks good hit okay And now if we were to edit our variables again, you can see we have a new option or Addition at the bottom there. All right. Very cool. So now if I just open up a command prompt here We should be able to do a Python Dash version And is it dash dash? Yeah, there you go dash dash version so that that basically proves that Python is now installed in our environment Variable is all hooked up. All right, so the next step is to And you don't have to do this, but I highly recommend doing it if you wanted to start to create GUI application that connects your different digital content creation packages like my or max or Houdini To allow it as like a bridge basically to pass data back and forth between Unity and your DCC packages All right, so let's take a look at that here in the next section here All right, so the last step here on the Python side of things is we should go ahead and install the pi side module so we can Look at the pi side example here. This allows us to create GUIs that control our DCC application So we have a live link between the two and so in order to basically utilize this Package which seems to be missing right now. That's pretty funny We need to be using a pi side so and we're not going to do that in this particular video We'll do it later later on down the road, but I just want to get it installed so you guys can see So to do that what we're going to do is launch command prompt because we can install it from here You can also do this in Visual Studio code, but I'm just going to do it from the command prompt So you just do Python dash M Pip then install and we want to install the pi side module now I already have it installed and so it's going to tell me that It's already satisfied in your case if you haven't installed it already It'll run run through doesn't take very long maybe a couple minutes at most and so once it's done then you have all the Requirements for Python for unity. So at this point It's good to move on to the next step and get a new unity project set up And then we got to install the Python for unity package Manually because it's not a part of the package manager. All right, so let's take a look at that on the next step All right, so go ahead and launch the unity hub This will allow us to create a new project and so I'm going to create a new unity project for unity 2020.1 I tested it out already so and I know it works. And so I'm going to call this unity For Python for unity. Sorry about that Python for unity And I'm going to hit create and once that's done. I will be back All right, so my project finished being created and now So like I was saying before It's the Python for unity is not in the package manager So if we were to open up the package manager here and try to search for it in the new Product or package manager. I should say let's go to unity registry and then we also need to make sure that we turn on our preview packages And if I were to look for Python There are no results and that's because it requires all this other, you know set up According to what I read on the forums at least They are not going to be putting it into the package manager at least not right now So in order to get it set up. I need to shut down my unity and actually add on to the Manifest.json file. So we have to actually put this at the very top of our Json file. So let me walk you through that. I'm going to open up my documents and go to my Unity projects here. So Python for unity go to packages and then we want to open up our manifest Json file. So I'm going to open that with code and this is just one I have from a previous test so I'm just going to copy this line right here and There we go. So I'll put that into the description for the video. Alright, so once you have that set up we need to go back and Launch our project. So I could just come into this folder here and just launch the sample scene And what's going to happen is it's going to launch unity and then install the package because now the manifest has been updated All right, and so once that is done, I will be right back And there we go. So now you can see we have this preview packages Displaying now, so I'm just going to dismiss that also in the console. You might see all these new errors here And the reason why that's happening is because it can't find the Python executable even with the environment path set up So if I were to go into my project settings now There's a new option in there for Python for unity like so and this is the issue right here I can't find that particular executable. So all we need to do is just point it to the folder So I'm just gonna set it there It says restart unity to use new Python. So I'm going to restart it one more time And be right back All right, so I restarted and everything is good to go. So now if we go up to Window and we go to our general option here And then you'll notice that there is a new Python console option here, which is awesome This allows us to type in, you know, really just tiny Snippets of Python. So if I do something like print Hello Python And then do a control enter you can see it pops it up right there Pretty cool stuff. All right. So now we actually have the ability to you know, write some Python inside of the unity editor And that's really just the beginning what we want to do now is we want to actually get a little bit better understanding of how We go about using Python scripts inside of you. Now, I should say this is only an editor side thing. This is not for a runtime thing it's really just for editor stuff and tools and communication between Maya max or Houdini All right. And so I want to do a couple things here I'm going to go create a new folder and I'm going to label this Python and I'm going to put a bunch of Python scripts in here And so what I want to do is go back to code over here And I'm going to close out my two manifest files here and I'm going to open up a folder And that folder is going to be The Python folder that I just made so I'm going to go to my Unity project and Go in assets and Python and there you go Awesome So what we want to do is we want to start to create Some interaction between C sharp and Python and learn how to work with objects in the scene and stuff like that So let's do that in this next step So what we need to do is we need to create a Python file So I'm going to come in here to my open folder. This is remember this is the folder inside of Unity and I'm going to create a New Python script called log names and what it's going to do is it's going to look into the scene and find all the game objects and then Log all of their names to the console And so the way that we get this to work So we first need to import the Unity engine module. So you say import unity engine and I'm going to just Cast it to a shorter name called you you just so I don't have to type out unity engine every single time and I didn't want it to complete that so you eat there we go All right, so then what I want to do is Down here. I want to find all of my objects and so to do that. It's just like what you do inside of C sharp, right? And in this case, this is a very simple example And I know you could you could do this in C sharp There's just really to show you how you can start using Python instead of Unity with the new preview package And so I'm going to do you eat dot objects Actually, it's object dot find objects of type like so and that type is going to be ui dot game object All right, so just like in C sharp exit We have to just utilize the ui module and then the classes inside of that and so with that we can do for geo for game object in objects Like so and all we want to do is just print their names. So I'm gonna say geo dot name like so Easy peasy. All right, so Just know that you can access pretty much all of those C sharp Functions that we use usually in our C sharp scripts here inside of Python, which is I find really really cool gives you lots of Opportunities for different types of tools that you can make So with that said now we can come into that Python console and we can load up that file All right, so I can load up log names like so and then just do a control enter and We get an error there and it looks like What was it telling me here? And it looks like it doesn't actually like the print in there. So let's go back to code here. We can actually do debug log That's what I wanted to do anyway. So you say you we for you engine debug log and we'll do geo dot name We'll save that. Let's go back to unity and let's just clear out our code. Let's load the file now and Make sure we fix the name here And we're still getting that error there and that is because I need that This is a capital there we go All right, so let's go back and fix all those guys in the code Side of things just need to make sure my syntax is correct There we go Save that Then let's test it out one more time. Let's clear our console here. I'm gonna load This guy and do a control enter. Yeah, there we go. So now if I were to add a Couple more objects in here. Let's just do this really quick here Create a couple boxes and just run that and you can see we get all those Names printed out to the console. So this is really cool But I don't want to have to constantly use the Python script editor to do this What I really want to do is attach it to a tool Some editor tool. All right, so let's do that. I'm gonna hide this as well So let's go and add our editor folder so we can make an editor script here really quick and I'll create I just I'm just gonna do a really quick Let's do a Python manager. I'm just gonna do really quick inspector and then So that's the C sharp script side of things And then I want to do the editor script. So we're gonna do Python manager editor like so And I'm using my snake case for my C sharp files Not terribly or anything like that. It's just go back and forth between Python and C sharp so much I get my Syntax or my naming conventions. I'll mix that All right, so I'm gonna let the little studio open here. I'll be right back all right, so in the Actual script the game of the mono behavior. I'm just going to remove everything. I'm just making really quick inspector editor I could have done a window as well. It just takes a little bit longer And then let's open up our Editor and this needs to extend editor, which means we need the you need the editor namespace Like so and we'll get rid of all of our built-in methods here and Now what we want to do I am going to create a Target variable and so to do that. I want to do the Python manager call this a target manager Is equal to target or nothing like right off the bat. So I'll do void on enable And I will populate that so we're gonna say target manager Is equal to target which comes with the editor namespace there and we need to make sure we cast it to the appropriate type and Then we're going to do our public override on inspector GUI and I am going to add a button so we can launch our Python script without having to open up that Python console Cool, and so all I need to do really just for this basic example is create a button. So It's gonna be our button and I'm gonna call this launch Python script And I'm gonna add a height to it All right, let's do that one more time there So I'm gonna do height And I usually put in something like 35 for this Cool, so now we have our button. So now we should get we can just log something here so I just want to do a log and Let's log Something like this is working All right, so let's go back to Unity and get that all set up just so we can see our button Cool, so let's create an empty game object. I'm gonna call it the Python manager Like so and then drag and drop my Python manager on to that And we actually need to go back to our editor script and we need to make this a custom editor so we need to custom editor type of Python manager like so There we go Now if we go back to Unity, we should see our button And we just need to re-select it. There we go. Yeah, so now we're working very cool so what I do now is we want to Click this button to launch our Python script and it'll print out so we don't use that Python console So I come in here. We need to actually include a Different namespace so we need the Unity editor dot scripting dot Python namespace for this to work and One thing we need to do Let's get the application path So I'm just going to do string path Is equal to application dot data path All right, so that should give us The assets because remember our Python script is in our assets folder. So let's just Log the path just to make sure Let's go back to Unity over here and click that Yeah, so now we have it pointing to assets and so all we need to do is append on The Python and then log names dot py file Because we are going to be using the Python File runner and if you actually go to if we come up here to the documentation Yeah, we wanted to use the Python runner run file. All right, so this is basically what we are doing right here Okay So let's do that. We want to come down here and I think I'm just going to concatenate this on here So I'm just gonna do plus Python forward slash log names. No reason to get all fancy for now And then we want to do the Python runner dot Run file and then you just pass in that path to the file Like so Let's go back to Unity and test that out All right, so let's select this guy. It's clear our console and launch a Python script and it says we didn't find the File because I am missing a forward slash there. So let's put that in there. There you go Try that one more time There you go. So now we're launching the Python script using Python for Unity So hopefully guys found that somewhat instructional. I know it's quite a bit of steps there This is definitely still very very preview package But I'm really excited because then what I want to do is I want to hook up Houdini with Unity so I can just start passing stuff back and forth and not really have to rely on the Houdini engine all the time All right, so super cool stuff. Thanks so much