Once you set up AI Toolbox, you can start using it to generate and edit C# scripts, generate images, shaders and UI documents for your Unity projects.

Generating Scripts

To generate a script with ChatGPT or Gemini, you’ll need to open the prompt window. There are two ways to do this:

  1. In the Unity Editor, select a GameObject and click the “Generate Component” button in the Inspector.
  2. Type a prompt describing the C# script you would like the AI to generate.
  3. Click “Generate”, and the script will be automatically created.

Press Generate Component button to open the prompt box

Alternatively, to open this window you can right-click in the Project tab ▶︎ select Create ▶︎ click C# Script by ChatGPT or use the shortcut: Alt+Shift+S (Windows) or Option+Shift+S (Mac).

Type your request in the prompt window and click “Generate and Add” to start the script generation process. You can also use Ctrl+Enter (Windows) or Cmd+Return (Mac). The generated script will be added to your project (by default in Assets/Generated, but you can choose the destination in the Output Path field in the General Settings).

The prompt window

The prompt window

  • Advanced Options — if expanded, reveals the Temperature, Timeout, History parameters, How To Write Prompts button , mirrored from the Settings panel (which can be found in Edit ▶︎ Project Settings ▶︎ AI Toolbox).

  • Save to History — enable this option to save the generated script to the history. History can be accessed with the “History” button in this window or in the Settings panel.

  • Chatbot - the menu for choosing the Backend for generating the scripts. Currently, there are two options: OpenAI ChatGPT, Azure ChatGPT and Google Gemini. The default chatbot is OpenAI ChatGPT. The Backend used for Chat with AI can be changed in Chat with AI window’s Settings.

The prompt window with advanced options expanded

The prompt window with advanced options expanded

Editing Scripts

If you would like to change any script (either AI-generated or human-written), click the “three dots button” on the script on the Inspector panel and select Edit Script with ChatGPT. This will open the prompt window. To enable or disable auto-accepting of the edits, please go to the General Settings and check the Auto-accept edits checkbox.

Edit the generated script method 1

Edit a script (method 1, from the Inspector panel)

Alternatively, you can select this scipt in the Project tab ▶︎ right-click on it ▶︎ select Edit C# Script with ChatGPT. This will open the prompt window.

Edit a script method 2

Edit a script (method 2, from the Project tab)

Once the prompt window is open, you can edit the script and click Generate to start the generation process. You can also use Ctrl+Enter (Windows) or Cmd+Return (Mac).

  • Left/Right Arrow Buttons — view the previous and next prompts from History.

  • Advanced Options — if expanded, reveals the Temperature, Timeout, History parameters, How To Write Prompts button , mirrored from the Settings panel (which can be found in Edit ▶︎ Project Settings ▶︎ AI Toolbox).

  • Save to History — Enable this option to save the generated script to the history. History can be accessed with the “History” button in this window or in the Settings panel.

The Edit Script prompt window

The Edit Script prompt window

AI Toolbox looks whether the generation is going successfully or it is going to have potential errors. If the script generation went without errors, by default you will have a new script in your project (by default, in Assets/Generated, but you can choose the destination in the Output Path field in the General Settings). If you have the Auto-accept option turned off, you’ll be presented with an according window in the end each generation process. To change this option, go to the General Settings and check the Auto-accept new files checkbox.

The window showing the successfully completed script generation (Auto-accept option is ‘off’)

  • Edit Prompt - This will open the prompt window containing the prompt text that was used to generate the script.
  • Reject - This will discard the changes made by editing the script.
  • Open File - This will open the script file in the default text editor.
  • Accept - This will accept the changes to the script.

If Editing the Script Results in Errors

AI Toolbox sees if the code that is being generated has errors and does not compile. AI Toolbox will give a few options to address that. If you have any errors when the script is generated, the look of the script generation window will change to the following:

The Edit Script prompt window

Generation window with errors

  • Ask ChatGPT to Fix It - This will submit the current code along with the error description and will ask AI to fix the code.
  • Revert and Edit Prompt - This will discard the changes made by editing the script.
  • Accept and Edit File - This will accept the changes and will open the script file to be edited manually. This option is useful if you want to fix the error yourself.
  • Accept - This will accept the changes as is and save the script.

Generating Images with DALL•E

AI Toolbox can generate images using the DALL•E. You only need to write a text description of the image you want it to produce. The prompt can be as simple as “A brick wall texture” or as complex as “A futuristic retro space ship landing on a snow-covered planet”. The more complex the prompt, the more specific the image will be.

To open the DALL•E generation propmt window, right-click anywhere in the Project tab and select Create ▶︎ Texture by DALL•E.

'Generate texture by DALL•E' menu item

‘Generate texture by DALL•E’ menu item

You’ll need to type your prompt in the prompt field and click Generate to start the generation process. You can also use Ctrl+Enter (Windows) or Cmd+Return (Mac).

  • Resolution - Opens a drop down menu where you can select the resolution of the image to be generated. The options are: 256x256 px, 512x512 px, 1024x1024 px. These are all resolutions that DALL•E currently supports.
  • Tileable - Generates a texture that can be seamlessly tiled.
    • Seam Size - The size of the seam if Tileable generating is enabled. The default value is 0.05.
  • Left/Right Arrow Buttons — view the previous and next prompts from History.
  • Advanced Options — if expanded, reveals the Timeout, Save to History parameters, Settings button and How To Write Prompts, and History buttons, mirrored from the Settings panel (which can be found in Edit ▶︎ Project Settings ▶︎ AI Toolbox).

'Generate texture by DALL•E' menu item

DALL•E prompt window

When the generation is completed the following menu will appear:

  • Prompt field - This is the field where you can edit the prompt.
  • Save and Regenerate - This will save the generated image to the folder set in Output Path (by default, it is Assets/Generated) and will generate another image without closing this window.
  • Discard and Regenerate - This will discard the generated image and will generate another image without closing this window.
  • Done - This will close the window and will save the generated image to the folder set in Output Path (by default, it is Assets/Generated).

'Generated texture window' menu item

Generated texture window

Generating Shaders

You can generate shaders with AI Toolbox. To do that, you need to have a prompt that contains the text description of the shader you want to generate.

We’ve found that the best way to have successful results is to generate a very simple shader and then gradually add more complexity using the Follow-up button, which appears upon every generation process completion (described below in this paragraph), or you can use the Edit Shader feature.

Please note that the outcome of the generation process completely depends on the AI model’s code writing abilities.

To open the shader generation propmt window, right-click anywhere in the Project tab (or click + there) and select Create ▶︎ Shader ▶︎ ChatGPT. Alternatively, you can go to Window ▶︎ AI Toolbox ▶︎ Generate Shader.

Shader generate menu item, method 1

Shader generate menu item, method 1

Shader generate menu item, method 2

Shader generate menu item, method 2

Once you have your prompt, click Generate to start the generation process. You can also use Ctrl+Enter (Windows) or Cmd+Return (Mac).

Shader generation prompt window

Shader generation prompt window

When the generation process is completed, a menu will appear with the following options:

  • Edit Prompt - This won’t save the shader and will open the prompt window where you can edit the prompt to make another generation attempt. Shortcut: Backspace.
  • Reject - This will reject the generated shader and will close the window. Shortcut: Esc.
  • Follow-up - Iterate with ChatGPT on the generated code.
  • Open File - This will open the generated shader file in the default application for the file type. Shortcut: Ctrl+Enter / Cmd+Return.
  • Accept - This will save the generated shader and will close the window. Shortcut: Enter.

The menu after the shader generation

The menu after the shader generation

Editing Shaders

With AI Toolbox, you can edit shaders with ChatGPT. To do that, you need to select a shader file, on the Inspector panel you should see the Edit Shader with ChatGPT button.

Edit Shader with ChatGPT button

Edit Shader with ChatGPT button

ChatGPT will edit both human-written and generated shaders.

Chat with AI

With AI Toolbox, you can chat with ChatGPT and Google Gemini within Unity. You can ask AI to explain the code, ask it for a list scripts to implement for a certain feature, an advice on game mechanics, etc. You even ask questions unrelated to Unity, just make sure to uncheck the Unity developer checkbox in the Settings foldout.

If the AI outputs any piece of code, you have an option to save it as a file in the project.

To open the Chat with AI window, go to Window ▶︎ AI Toolbox ▶︎ Chat with AI, or use the shortcut: Alt+Shift+C (Windows) or Option+Shift+C (Mac).

Chat with AI menu item

Chat with AI menu item

Once you open the chat window, you are good to ask away. You’ll see the Send a message field where you can type your message in the bottom of the window. Type your prompt and press the send button, shortcut: Ctrl+Enter (Windows) or Cmd+Return (Mac).

  • ‘Pencil’ button - Edit a previous message to make another generation attempt.
  • Copy button - Copy the AI response to clipboard.
  • Save button - Saves the code within the AI response as a file in the project. The file name is generated by AI.
  • Regenerate response - Tries generating another variation of the reply from AI to your latest prompt. If the Temperature is set to 0 in the Settings foldout menu (described below), this will generate the same response.
  • ‘Paper airplane’ button - Send the message. Shortcut: Ctrl+Enter (Windows) or Cmd+Return (Mac).
  • Settings - Expands and collapses the foldout menu revealing the settings applicable to the chat.
    • Unity developer - AI assumes a role of a Unity developer. If disabled, AI has no specific role.
    • Temperature - Controls randomness. Lower values result in less surprising answers. As the temperature approaches zero, the model will become deterministic and repetitive. Higher values result in more random answers.
    • Chatbot - Select the AI Backend to use for generating the responses in freeform chat. Currently, there are the following options: OpenAI ChatGPT, Azure ChatGPT and Google Gemini. The default chatbot is OpenAI ChatGPT. This selects the chatbot for the chat only — the chatbot used for other generation purposes (scripts, images etc) can be changed in each of those windows’ settings.
    • Model - Select the GPT model to use. Currently, there are two options: GPT-3.5 and GPT-4. The default model is GPT-3.5.
      Edit Shader with ChatGPT button
  • Clear - Clear the chat history.
  • ‘Download’ button - Export the chat history to a file.
  • GPT model (on the window footer) - Indicates which chatbot and model is being used for the chat generation.

Chat results including code explanations, how-to’s, etc largely depend on the GPT model you are using.

An example of coversation with ChatGPT (GPT4 model used)

An example of coversation with ChatGPT (GPT4 model used)

The Chat with AI window is dockable and can be placed anywhere in the Unity Editor so that you always have access to it.

  • Submit Script foldable menu is used to provide any script to the chatbot as context to the conversation. Select the script file in the File field (or drag and drop the script onto it) and either send a message with your question, or select one of the pre-defined questions using the buttons below.

Options to operate on files

Options to operate on files

AI Toolbox Settings

All settings can be found in Edit ▶︎ Project Settings ▶︎ AI Toolbox.

OpenAI API Key

  • API Key is the field where you will need to paste your API Key, once it is generated (here is more info on API Key generation).
  • Use Proxy Server - Use the proxy URL for the OpenAI API. Once you click the Use Proxy Server button, the short guide on how to obtain a free API key will appear.

Proxy Server settings and guide

Proxy Server settings and guide

⚠️ The API key is stored in the following file: UserSettings/AiToolboxSettings.asset. When sharing your project with others, be sure to exclude the “UserSettings” directory to prevent unauthorized use of your API key. Even though the API key is encrypted, any client-only security measure can be circumvented.

OpenAI ChatGPT API Key and other settings

OpenAI ChatGPT API Key and other settings

  • Model is the GPT model that will be used to generate scripts. Currently, there are two options: gpt-3.5-turbo and GPT-4. The default model is gpt-3.5-turbo.
  • Model version — the version of the model to use. This list is constantly updated with the new versions as they are released. More on Models here
  • Extended context Uses a variant of gpt-3.5-turbo that can work with much longer code. It allows 4 times more context, handling up to 20 pages of text/code in a single request. However, it costs twice as much: $0.003 per 1K input tokens and $0.004 per 1K output tokens.

Microsoft Azure

You can access ChatGPT using Microsoft Azure. It provides the same models as OpenAI, but has more control over the backend. Plus, it’s also very cheap and has a one month free trial. The detailed step-by-step guide on the Microsoft Azure setup is here.

Azure ChatGPT API Key and other settings

Azure ChatGPT API Key and other settings

Google Gemini

You can use Google Gemini AI model to generate scripts and chat with AI usin this GPT. The detailed step-by-step guide on the Google Gemini setup is here.

Gemini API Key and other settings

Gemini API Key and other settings

Generation Settings

  • Default temperature controls randomness: higher Temperature results in more random completions. As the Temperature approaches zero, the model will become deterministic and repetitive. Lower the Temperature to get more or less the same results when you re-iterate script generation. Raise the Temperature to get more diverse, creative and surprising results upon each completion. Current default Temperature is 0.

Temperature parameter

Temperature parameter

Guiding Prompts

Guiding Prompts are used to help the model produce results that are more relevant to your project. All guiding prompts are submitted to AI along with every prompt you type in the prompt window.

  • Result Type - this is the drop down menu where you can recall the predefined guiding prompts for different types of generated files (scripts, shaders, UI documents and textures).
  • + and Trash Bin buttons add and remove guiding prompts.
  • Checkboxes enable or disable guiding prompts without deleting them.
  • Reset to default resets the guiding prompts to the default values.

Guiding Prompts settings

Guiding Prompts settings

The Result type drop down menu contains the guiding prompts currently used for Components (scripts), Shaders, UI Documents and Textures.

Guiding Prompts Result types drop down menu

Guiding Prompts Result types drop down menu

General Settings

  • Timeout - if enabled, the Duration field appears. If AI doesn’t respond within the Duration parameter of the Timeout, generation fails. Try increasing this value if ChatGPT or Gemini often outputs a ‘timeout’ error. If that does not resolve it, please take a look at this paragraph. If disabled, the generation process will wait for a response from AI indefinitely.
  • Duration - is the time in seconds that AI Toolbox will wait for a response from ChatGPT or Gemini.
  • Output Path - is the path where generated files will be saved when you use the “Generate Component” button in Inspector. By default, it is set to Assets/Generated.
  • Inspector button - if enabled, the “Generate Component” button appears on every Game Object’s Inspector panel.
  • Auto-accept new files - if enabled, AI Toolbox will automatically save generated scripts into the Unity project. If disabled, script generation window will stay open and you will be able to choose a further action with the script.
  • Auto-accept edits - if enabled, AI Toolbox will automatically save script edits to the edited file. If disabled, script editing window will stay open and you will be able to choose a further action with the script. More info about these actions can be found here.

General settings

General settings

Prompt History

  • View History shows the history of the prompts you have used to generate assets as well as the settings used for each prompt.
    • Guiding Prompts foldout - expands/collapses the set of guiding prompts used in the generation from that particular prompt.
    • Delete - deletes the prompt from the history.
    • Copy - copies the prompt to the clipboard.
    • Clear History - clears the history.

History settings

History settings

History window

Prompt History window

  • How to write prompts opens the How to write prompts page of this documentation in your browser.
  • Discord opens AI Toolbox support Discord channel in your browser.
  • Asset Store Page opens the AI Toolbox Asset Store page in your browser.

Useful Links

Useful Links

Troubleshooting

Please check the FAQs page, where the most common issues and their solutions are described. If you still have questions, please contact us.

Comments