 What's going on everybody? It's Cetanmer and welcome back to my channel. So in today's video, I'm really excited to show you a prototype that I created by using ChatGPT in Unity. And the way that it's going to work is we're going to be telling ChatGPT a series of questions. ChatGPT is going to respond to us with code that is generated based on the criteria that we included in the questions. And then ultimately we're going to be able to run this in Unity at runtime. So let's jump into my computer and start looking at it. All right guys. So the way that this works is I have a service that communicates with ChatGPT. So what I'm going to do to start, I'm going to say Python and then ChatGPT underscore service. And it's going to be exposing an IP address and also a port which you guys can see here is 127, that's 001, 4500. And if I go into Unity, you're going to see that I have these ChatGPT settings which also posts a message to that same IP address. And then the endpoint is going to be questioned. I also have a set of reminders in here just to make sure that I don't get explanation back. I also get code in a form of markdown. So I can basically parse it and make sure that it doesn't forget namespaces, which it tends to do that. And also make sure that it uses the animator methods and includes a yell. There's just a couple of things that I found that it was having issues with. So to run it, I can just hit play and ask ChatGPT a question. So the question, I'm basically passing it to this component called ChatGPT tester. And you can see that I'm saying what the question is going to be in a form of a scriptable object. I also have a scenario title because I want to display that information here on the UI. And also what I wanted to create. So I'm saying create a Unity C sharp script, bono behavior, name. And then I have variable names that I am basically replacing a runtime when this code gets generated from ChatGPT. So you can see that I have class name here. I wanted to the class to be called CarCreator. I also want these to basically call an import model once that code is generated. It basically is going to use a broadcast message method to be able to do that. I also want to search for an entity, which is a Jaguar, in this case, that is going to be the car that I want to download from Sketchfab. And I also wanted to generate a method called apply, so that I know which method I can call when the code gets generated. So the way that it's going to work, I can say as ChatGPT. You're going to see here that it says generating code attempt number one, please wait. I also have multiple retries because if it doesn't work the first time, I want to append the exception and basically resend it back to ChatGPT. Just in case something doesn't work. So I have it up to three times and if it doesn't work at the third time, then I don't basically do anything more. So you can see that the car got basically the class got generated, which is in here. And that is the class that I told it to generate, right? It was a car creator class. I also wanted to have an apply method. And I also wanted to have a car, you know, of the model is going to be Jaguar. And you can see that it's, you know, it's moving in here because I told the generated code to basically animate these. And I think I just specified 25, I think it was 25 milliseconds. Every, I think it was, let me go ahead and look at it just to make sure. I think it was, yeah, it was three meters per 25 milliseconds. So if we look at the code that got generated in here, you're going to see what it's doing. So again, the class car generator, apply, I am calling, broadcasting a message called import model, which is going to be the method that I'm going to be calling. And then Jaguar is going to be the model name that I want to download from Sketchfab. And then I'm also executing a core routine, which this is all generated by ChatGPT. I didn't, I didn't do any of this. I just told it what to create. And you can see that it's doing a while looping here. And then it's looking for the word Jaguar. And if it finds a game object, Jaguar, then it's going to basically move it. I think it's, yeah, it's about three meters, every, you know, multiply by delta time. And then it's waiting 0.025f, which is basically what I told it to do. And it included all the namespaces that I want these to include, which is really, really powerful. So let's look at the areas in here of the question, right? I told it to create a mono behavior named class name, which is crack creator, which includes a method called action. And you can see the the method called action underscore apply, which gets replaced by the word apply. And then I also told it in here too, that the first argument was going to be the broadcast name, which gets replaced by import model. You can see that in here. And then the name of the single parameter was going to be Jaguar, which also got generated. And then I also told it, you know, make sure that you check every second for the search entity, game object, and it found constantly moving along the Z axis at three meters per 25 milliseconds, which is, you know, which is what it's doing. So this is really, really crazy. Let's go ahead and do another question. So I have multiple questions in here that I can ask it. Let's go ahead and do a question that is pretty simple. This one is going to be create a C sharp is create mono behavior named cube creator. And then which includes a method called apply. And then it creates a primitive sphere and rotates it continuously. So what we can do to test this is pretty easy. I can go back into my tester. I can select question number four, which is going to be, you know, the one that I just show you. And as soon as you do that, you can modify it in here because I have editor tools that allow you to see this information. Normally when you do a scriptable object, you don't see all the detail, but this information is included in here and how I did it. If you like this video, I can make more detailed videos on how this was all coded and a structure, but just know that this is going to be sent to chat GPT. So if we go here and say, okay, ask chat GPT, you're going to see that now we have, you know, our new question is going to be the scenario question is going to be that creating a cube and rotating it, which in this case, it was a sphere because I change it to a sphere, but I could basically change this and resend it. And you're going to see that instead of a sphere, we're going to be getting a cube. You can see I got a, I basically got a sphere. And if we get closing here, you're going to see that it's animating. And in this case, the code is not this code because I added basically a scrollable view. You can see the new code that came back from the service. Also here on the left side, you can see that this is a cube creator. Here's a new method. It's actually a sphere. And then this is a rotate sphere code. And I didn't tell it to do much. All I told it to do is rotate it continuously. And it just, you know, I just did it on his own, which was pretty, pretty cool. So let's say that we wanted to do that with an actual cube, which is what I originally had. So we can go back down here to the tester and then modify here. My question looks like I got a narrowing here. Let me make sure that, okay, it looks like I deleted the question for some reason. But the cool thing with this though is I can go in here and go into my service. And we can go in here. I don't want to include the additional rules. I can just copy that. And then come in here and then just paste it. And we can just change this to be, you know, I want to do a cube. Obviously, if you want to use the class names that are having here, we could do some something like this, which is, which basically gets replaced on the backend. I can say class name. And then I can also replace the apply method here with action, apply. And then we should be good in here. I think I got everything correctly. And then what I'm going to do here, this is actually, we don't want, we don't want it to create another cube creator. Let's say that I wanted to create a, I don't know, cool creator. And it's going to basically change the name of the class. So I can go back here into my tester. And you can see that that's, you know, that's what we just added. We change it to a cube. We have cool creator. And I can basically just add another question. I'm going to say ask a question. And you can see that the service got my new questions. And then the additional rules that I have in, you know, when I send the message. So if you want to look at the additional rules, you can go here into chat GPT settings. And these are all the different rules that I have. And I call them reminders. And they're basically just things that get appended at the end of the question. And you can see that now we have a cube and it is rotating. We also get the new question here of the code that got generated. So another thing that we can do is we can go back in here. Let's do another, I think a cooler one, which I think we do question two. It's more intense. It's going to be a church. And it's going to have a broadcast name, which I show you before. And the entity is going to be a church that this model is basically pointing to a sketchfab. And that's why we're getting an actual 3d model that gets search on a sketchfab and then download it into unity by using a different component, which I'll show you in the diagram in just a minute. But we can go ahead and change this question to be question number two, which I think it's cooler. We can just say as chat GPT. You can see the new question was sent to chat GPT service. And we can also see it in here editing here so that I could actually see what it was doing. You can see import a church and rotate in it. Let's just wait until this completes. Okay, so looks like we got that question. The actual code generated back. And you can see that we now have a search for something that was basically flagged as a church. And we have, you know, we have the church. I think it's part of a church that got generated. But you can see the game object is in here. We could technically, you know, move it around. I'm also going to move it. We can just move this guy over there. Maybe we can move that guy over there. And let's try this question one more time. Because it's going to randomly select a church from Sketchfab and then download it back into Unity. So you can see same question was sent to the chat GPT bot. And you can see that this is a code that got generated. We got rotate church. And then we just have the word church. I think it's in this case, it's going to replace church because we already have a model of that type in here. You can see that it's downloading. I also added a downloading, you know, progress so that I could see what this was actually doing. So let's wait. I think this one is going to be a cooler model. I think it's larger than the one that we just imported. All right. So here's the other model that got generated. This one is a lot larger. So I had to zoom out. But you know, some idea, I found a different model, brought it back into Unity. And you can keep playing just to see what kind of models it gives you. So we could technically go back into our question here, number one, and change this to be a different car. Maybe we wanted to do maybe like a Ferratty. We can just say, you know, this is a Ferratty creator. We can technically just delete this church here because it is taking a lot of resources. And then go back into my tester here, change this to be question number one, or if you wanted to clone it and credit me a question, you can also do that. I can just say ask chat GPT. And you can see that we're now sending the word Ferratty. And, you know, everything else is going to be the same because that's, you know, the only thing that I change also changed the name of the mono behavior that was going to be generated. We can also go back here into our logger so we can see as the questions get generated, what we're getting back, or you can look at the code that gets generated and send to the service. So you can see that now we have now Ferratty creator, mono behavior, broadcast message, Ferratty. And we actually got a really cool model in here that we can look at as well. And obviously I don't have animations on the tires. We can tell it to do cooler things if we wanted to. And we can just turn off the lighting here so we can see it better. You can see the card that came back. That is really cool for prototyping, right? This is really, really powerful. You look at the chat GPT tester component, which is basically a mono behavior that sends a series of, you know, recommendations or rules. And that information gets into this class, which is called the chat GPT client. Chat GPT client says, you know what? Chat GPT, which is the cloud service where you go into openai.com and basically, you know, you type it all in. I'm using a Python wrapper that gives you that information. It basically uses a headless browser to communicate with it. It's not official, so I don't recommend that you use that for production. You wait until chat GPT comes up with an API. And then you can use that. But basically that calls into that. And then once we get the response back, I get the generated code, which I execute in Unity by using a Rosalind compiler that I got from the Unity asset store. Then once the generated code is there, I have the import model method that I show you in Unity. If you go back into the tester, you can see that this is basically broadcasting an import model. So in Unity, I actually have that method that exists. So that method gets the basically the parameter either the Java, the Ferrari, or any type of model that you want to import. Then that calls into a Sketchfab client. Sketchfab client communicates with Sketchfab. Then Sketchfab provides a series of endpoints. One of them was, you know, to search for a model. Once you search for a model, it basically gives you a download URI. You can do an HTTP call to basically get the Z file. I download the Z file and then I load it by using glt-fast. And then glt-fast says, okay, what is the name of the model? Where is it going to be located? And then based on the name that I got from Sketchfab, I just create these different objects. Then in the generated code, I just look for those objects. And then once they exist, right now I'm just doing rotations of movements. Obviously you can do a lot more complicated things. But that's really how this works is pretty straightforward. It took a little bit of time to get it all working. But if you want to know more about how this works, and if you're interested in me going into detailing, you know, every step of the process, let me know in the comments and I'll be more than happy to do that for you. Thank you very much, guys.