AI DevKit
Glitch9 Inc.Glitch9 DocsDiscordIssues
  • Introduction
    • AI DevKit 3.0
    • Update Logs
    • Troubleshooting
      • ❗Issues After Updating AIDevKit?
      • ❗The type or namespace name 'Newtonsoft' could not be found
      • ❗Build Error: The name 'UnityMenu' does not exist in the current context
      • ❗Model 'modelName' not found
      • ❗The model `model name` does not exist or you do not have access to it
      • ❗The type or namespace name 'AndroidJavaObject' could not be found
      • ❗The type or namaspace name 'Plastic' does not exist
      • ❗Build Error: The name 'Asset Database' does not exist in the current context
      • ❗'ModelData.Create(Provider, string, UnixTime?, string)': not all code paths return a value
      • ⚠️ Timeout Issues
      • ⚠️ Receiving a “HTTP/1.1 400 Bad Request” Error?
    • FAQ
      • My OpenAI API free trial has ended or is inactive.
  • Quick Start
    • Get API Keys
      • OpenAI API Key Guide
      • Google API Key Guide
      • ElevenLabs API Key Guide
    • Text Generation
    • C# Object Generation
    • Image Generation
    • Sound Effect Generation
    • Text to Speech (TTS)
    • Speech to Text (STT)
    • Voice Changer
    • Audio Isolation
  • Pro Features
    • Generation Menu
      • Code Generators
        • C# Script Generator
        • Unity Component Generator
    • Editor Chat
    • Editor Vision (TTI, ITI)
    • Editor Speech (TTS)
    • Management Tools
      • Prompt History Viewer
      • AI Model Manager
      • TTS Voice Manager
      • OpenAI File Manager
      • OpenAI Assistant Manager
      • ElevenLabs Voice Library
  • Assistants API (OpenAI)
    • How it works
    • Creating custom functions
    • Creating assistants API
  • Advanced API Supports
    • OpenAI API
      • 💬Chat completions
      • 🖼️Image operations
      • 🗣️Text to speech
      • 🎙️Speech to text
        • Recording real-time in Unity
      • 💾Files
      • 🔎Embeddings
      • 🛡️Moderations
      • ⚙️Fine-tuning
    • Google API
      • 📝System instructions
      • 💬Text generation
      • ⚙️Fine-tuning
      • ▶️Fucntion calling
      • 🔎Embeddings
      • 🛡️Safety
      • 💻Code execution
    • ElevenLabs API
  • Legacy Documents
    • AI DevKit 1.0 - 2.0
      • AI DevKit 2.0
      • AI DevKit 1.0
      • Preperation
      • Event Handlers
      • Scriptable Toolkits
        • Chat Streamer
        • Image Generator
        • Voice Transcriber
        • Voice Generator
      • Editor Tools
Powered by GitBook
On this page
  1. Quick Start

C# Object Generation

Object Generation lets you turn natural language prompts into strongly-typed Unity C# objects by guiding the AI to return JSON that matches your class definition.

It's perfect for generating game data like:

  • 📦 Items

  • 🎮 Quests

  • 🗨️ NPC Dialogue Trees

  • 📋 Skill Definitions

  • 🧠 AI Configuration Profiles


✅ How It Works

  1. Define a C# class with special attributes

  2. Call .GENObject<T>() with a descriptive prompt

  3. AI returns JSON, which is parsed into a T object using JsonConvert

🔒 Schema guidance ensures the AI produces valid JSON matching your structure.


🚨 Required Annotations

Provider
Required Attribute

OpenAI

[OpenAIJsonSchemaResponse(...)] (on the class)

Others (e.g. Gemini)

[JsonSchema(...)] (on each property)

These attributes are mandatory. Without them, the task will fail to register the schema.


🎮 Example: Generate an RPG Item

using Glitch9.AIDevKit.OpenAI;
using Glitch9.IO.Json.Schema;
using System.Collections.Generic;

[OpenAIJsonSchemaResponse("item_response", Description = "RPG-style inventory item", Strict = true)]
public class GameItem
{
    [JsonSchema("id", Description = "Unique item ID", Required = true)]
    public string Id { get; set; }

    [JsonSchema("name", Description = "Name of the item", Required = true)]
    public string Name { get; set; }

    [JsonSchema("rarity", Description = "Item rarity", Enum = new[] { "Common", "Uncommon", "Rare", "Epic", "Legendary" })]
    public string Rarity { get; set; }

    [JsonSchema("effects", Description = "List of effects applied when used")]
    public List<string> Effects { get; set; }
}

✅ Unity Usage

GameItem item = await "Generate a legendary sword with magical effects"
    .GENObject<GameItem>()
    .SetModel(GPTModel.GPT4o)
    .SetTemperature(0.4f)
    .ExecuteAsync();

Debug.Log(item.Name + " - " + item.Rarity); // "Blade of Eternity - Legendary"

🧪 Example Output from AI

{
  "id": "legendary_sword_001",
  "name": "Blade of Eternity",
  "rarity": "Legendary",
  "effects": ["+50 Attack", "Fire Enchantment", "Life Steal"]
}

🎮 Example: Generate a Simple Quest

[OpenAIJsonSchemaResponse("quest_response", Description = "Basic RPG quest", Strict = true)]
public class Quest
{
    [JsonSchema("title", Description = "Quest name", Required = true)]
    public string Title { get; set; }

    [JsonSchema("description", Description = "What the player must do", Required = true)]
    public string Description { get; set; }

    [JsonSchema("objective", Description = "Main goal of the quest")]
    public string Objective { get; set; }

    [JsonSchema("rewardXP", Description = "XP rewarded upon completion")]
    public int RewardXP { get; set; }
}
Quest quest = await "Create a side quest for a fantasy game where a farmer asks you to find his lost chicken"
    .GENObject<Quest>()
    .SetModel(GPTModel.GPT4o)
    .ExecuteAsync();

🧠 Tips for Better Accuracy

✅ Tip
Why it helps

Use Strict = true

Ensures output matches your schema exactly

Provide clear, focused prompts

e.g., "Generate a level 5 healing potion item"

Use [JsonSchema] attributes

Describes intent to both AI and schema validator

Catch errors with try/catch

Handle malformed JSON safely in production


🧩 JSON Schema Attributes Cheat Sheet

Attribute
Use

Name

JSON field name

Description

AI guidance

Required

Ensures field presence

Enum

Limits possible values

Minimum, Maximum

For numbers

MinItems, MaxItems

For arrays

AdditionalProperties

Disable extra fields

PreviousText GenerationNextImage Generation

Last updated 18 days ago