Hello! Today's dialogue is about what everyone has started to use in one way or another. Artificial intelligence (AI) and how it is used in game development.I will warn you right away that I do not use generative AI for sprites or textures. But I started using it to write code, first out of curiosity and then more thoughtfully. And I will write about this experience today.
Is there any "moral" right at all in using AI to help write code? In fact, yes, since when you write code for a game or other program, you usually use already existing parts of code from other projects that someone used before you. Of course you can write everything yourself, but usually it won't be much different from what already exists.For a simple example, I'll show you the basic code for moving a 2D character in Godot:
This code is already automatically generated by Godot itself when you create a character. Here is the code I use:
As you can see, it is larger and calculates much smoother movement of the character. And here is the generative code:
You can notice that the default code and the generative code are not so different. If you ask why, then the reason is simple. My prompt for AI was: Generate code for moving a character in 2D - side scroller with a jump. And in fact it did the job, but it's nowhere near what my code does.AI performs only the tasks assigned by the developer and has no will of its own or even an idea of what exactly it writes. You need to understand this, after all, AI is now a simple algorithm that searches for the most optimal solution to fulfill the given task. This is not a real intelligence that can reason. But why is everyone praising it so much?Because understanding how it works and using it brings many benefits. The AI itself has no memory or understanding of project, but you can create it and use it in your development tasks. How to do it?It's quite simple actually, imagine that the AI is a dumb child that, although it seems intelligent, is actually not. You tell him to "go to point A and turn back", he will do it, but maybe he will go on his hands instead of his legs. Because you didn't explain that when you walk you need to use your legs. You again told him to "go to point A using your feet and turn back", he did so and walked to point A on his feet, but came back by jumping because that is more efficient. But it's strange, isn't it? So you again tell him "go to point A on your feet and come back the same way!" and only now he will complete the task as intended by you.In fact, this is prompt for AI and how AI understands it (simplified, but you get the general idea). And if you follow the thought, memory and understanding of the project can be created by instructing the AI about what is being developed. The better your instructions are written, the better he will perform the task you give him.In this way, you can create a special file with development rules (for example: Rules.txt) in which you write down what the AI should follow when generating code. For example:- Use only C# language- Use the Godot libraries as a priority, if it is impossible to perform the task with the Godot libraries, use the System Libraries.- ...You can also create an additional file (For example: Project Description.txt) in which you describe what the project is. Example:- This project is a puzzle game- This project uses the Godot engine version 4.6.2.- This project uses only one input for PC version - Left mouse button.- ...And the more you write in these files, the better. But as you can see, there is something hidden here that no one talks about. Without knowledge of development, code writing, project architecture, you will not be able to use AI effectively. Many people say that now you will be able to code games without knowing how to code, but this is a trap.An AI with well-written rules will perform your tasks effectively, but what happens when there are tons of errors?Ho-ho, this is where HELL begins. The AI can find the cause of the error when you give it the entire error text, but it has one problem: it's not trying to get rid of the error itself, but the error message. It's a little hard to explain because it's not entirely true, but I'll try.There is a situation with a simple error and a complex one.Here is a simple error for example:
There is simply a method call on a node that was not attached in the editor. A simple fix is to just specify the starting state in editor and the error will go away so the AI will point it out to you.But sometimes there are errors that arise not as a result of the developer's error, but the error of the engine itself. In my customization system there was an error that occurred only in the editor when changing the scene from one to another. And the AI immediately found that it was a signal connection problem and tried to fix it. But ... it did not change anything, and the error still says that there is a problem with the signals! Therefore, not understanding then, I forced the AI to fix the error. And the AI changed the signals, rewrote the initialization structure, etc. It eventually got rid of the error, but the customization system stopped working. The problem was solved, but at what cost...As a result, I had to undo all AI changes to a working state, and then sit down and look for the fix myself. The error wasn't really too big and it was just limiting the specific combination of the [ Tool ] tag and update signals (which is what the problem was about) and the fix only required changing a couple of lines of code. But I was able to solve this because I could search for similar problems on the Internet and analyze the written code.Although this is a specific error, but such errors occur all the time when you develop games. And although AI helps very well, it is not all-powerful, and it will not be able to replace the developer.Therefore, do not shy away from AI (for code generation), since even though it is a new thing, you will still have to learn the code to use it correctly. And sometimes what the AI writes can be a more optimized version of what you don't know yet. After all, its entire base is built on the work of people who have already created this code, and you can find most of it yourself on Git.