Here we condensed some useful bits of advice on how to write better prompts for AI Script Generator with more predicted and fitting outcome. You can get decent and perfectly working results if you know what to ask from ChatGPT, how well articulated your phrasing is and how specific you are.

Below you can find a few good articles and videos that shed some light on the topic. Thay are not exactly tailored for Unity, but you can get familiar with some of best practices and tips on how to write better prompts and iterate them.

Articles

Best Practices for Prompt Engineering with OpenAI API

How and Why to Use ChatGPT to Generate Code Snippets

Videos

Creating a Space Game with OpenAI Codex

Our tips

Be specific

Clearly describe the desired functionality, inputs, and outputs to help the AI understand your requirements. Mention any specific libraries, frameworks, or coding conventions you want to be used.

At the same time, try to keep your prompt concise and to the point. Too much information can be overwhelming and may result in less accurate code generation.

Your prompt should be long enough to describe the desired functionality, but not so long that it becomes difficult to understand.

Less effective ❌:

I want a script for a game where you play as a wizard.

Better ✅:

A character movement controller in a 3D action RPG game. The character can move and jump based on user input. Add paramaters to control the character speed and jump height.

Use proper grammar and punctuation

This is a very important aspect of writing a good prompt. The more grammatically correct and punctuated your prompt is, the better the results will be.

Spelling mistakes and typos will also affect the results, so make sure to proofread your prompt or use a spell checker.

Specifically, you should use proper capitalization and punctuation. For example, you should capitalize the first letter of every sentence and use periods at the end of every sentence.

Each prompt should be a complete sentence. This means that you should use a period at the end of every sentence.

Less effective ❌:

script that moves a game object from left to right over 5 seconds on the x axis and the object is a cube

Better ✅:

Script that smoothly moves a GameObject, represented by a cube, from left to right over a 5-second duration, along the X-axis.

Limit scope of scripts

Instead of providing a single complex prompt, break it down into smaller, more manageable tasks. This will make it easier for the AI to generate relevant code.

Separate functionality into different scripts whenever possible. This will make it easier for the AI to generate relevant code.

You can also use the “Edit Script” feature to modify the generated code. This will allow you to add functionality to the script in a more controlled manner.

Less effective ❌:

Character in a 3D action RPG game. The character can move, jump and attack based on user input. The character can also take damage and die. The character can pick up items.

Better ✅:

Character movement controller in a 3D action RPG game. The character can move and jump based on user input. Add paramaters to control the character speed and jump height.

Character attack controller in a 3D action RPG game. The character can attack based on user input. Add paramaters to control the attack damage and attack range.

Character health controller in a 3D action RPG game. The character can take damage and die based on user input. Add paramaters to control the character health and damage taken.

Character item controller in a 3D action RPG game. The character can pick up items it collides with.

Be realistic

Understand the limitations of AI-generated code and adjust your expectations accordingly. The AI may not be able to handle highly complex or specialized tasks, but it can be a helpful tool for generating basic scripts or providing a starting point for further customization.

Less effective ❌:

I want a script that can generate a city in a 3D game. The city should have buildings, roads, and other infrastructure.

Better ✅:

Script that generates a city in a 3D game. The city layout is a rectangular grid of buildings. Each building is a prefab with a random height and width.

Comments