Use Extend Codegen CLI to generate Unity SDK Plugin for Extend Service Extension
Overview
This article provides a step-by-step guide on how to generate a custom service plugin for the AccelByte Unity SDK using the Extend Codegen CLI template pack.
A custom service module allows developers to leverage the AccelByte Unity SDK to interact with custom service APIs. This includes services created with the Extend Service Extension, as well as any other custom service that provides an OpenAPI 2.0 specification.
The Extend Codegen CLI template pack consists of a Makefile and some Jinja template files. To generate the necessary code, simply invoke a single make command. This command triggers the Extend Codegen CLI to process the Jinja template files alongside an OpenAPI 2.0 JSON file, which outlines the custom service APIs, to generate the corresponding code.
Prerequisites
-
Extend Codegen CLI template pack ZIP for AccelByte Unity SDK.
The template pack contains a Makefile and Jinja2 templates that drive the code generation process.
a. Download: Get the latest
accelbyte-unity-sdk-template-pack.zipfrom GitHub Releases.b. Extract: Unzip to a working directory (e.g.,
~/Downloads/accelbyte-unity-sdk-template-pack/).c. Contents: The template pack includes:
Makefile- Build automation script that orchestrates code generationconfig.yaml- Configuration for Jinja2 template renderingtemplates/- Jinja2 templates for generating C# coderes/- Base package structure and resourcesversion.txt- Template pack version (e.g.,0.0.28)
tipThe
Makefileautomatically pulls the Docker image when you run themakecommand, so you don't need to manually download or install the Extend Codegen CLI. -
Windows 11 WSL2 or Linux Ubuntu 22.04 with the following tools installed.
a. Bash
bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
...b. Make
- To install from Ubuntu repository, run:
sudo apt update && sudo apt install make.
make --version
GNU Make 4.3
...c. Docker (Docker Engine v23.0+)
- To install from Ubuntu repository, run:
sudo apt update && sudo apt install docker.io docker-buildx docker-compose-v2. - Add your user to
dockergroup:sudo usermod -aG docker $USER. - Log out and log back in so that the changes take effect.
docker version
...
Server: Docker Desktop
Engine:
Version: 24.0.5
...infoThe
makecommand in the template pack uses Docker to run the Extend Codegen CLI. The Docker image (accelbyte/extend-codegen-cli) is automatically pulled if not already cached locally. - To install from Ubuntu repository, run:
-
AccelByte Unity SDK installed in your Unity project.
tipIf you haven't integrated the AccelByte Unity SDK yet, follow the Unity SDK setup guide first. The generated custom service plugin depends on the base AccelByte Unity SDK.
-
A valid OpenAPI 2.0 JSON file for your custom service.
infoIf your custom service uses the Extend Service Extension, an OpenAPI 2.0 JSON file is automatically generated when the app is deployed in AccelByte Gaming Services (AGS). To access it, open the AGS
Admin Portal, navigate to your app'sApp Detailspage, clickOpen API Documentation, and find the JSON file link at the top of the Swagger UI page.Alternatively, if you need to get the OpenAPI 2.0 JSON file before deploying your app in AGS, see here.
tipValidating your OpenAPI 2.0 JSON file: Before proceeding, validate your OpenAPI spec using tools like Swagger Editor. Invalid specs will cause codegen errors.
Generate Unity SDK Plugin for Extend Service Extension
-
Place the OpenAPI 2.0 JSON file for your custom service in the
my-unity-project/specfolder. In this example, the file is namedguild.json. Next, copy theguild.jsonfile into the following three folders:Client,GameServer, andModels./path/to/my-unity-project/
|__ Assets/
|__ Library/
|__ Packages/
|__ ProjectSettings/
|__ spec/
|__ Client/
| |__ guild.json <
|__ GameServer/
| |__ guild.json <
|__ Models/
| |__ guild.json <
|__ guild.jsonimportantThe Extend Codegen CLI template pack uses the OpenAPI 2.0 JSON file name as an identifier for your service: You can rename the file according to your preferences, but we recommend using all lowercase alphabets (a-z) to avoid issues generating code.
cautionWhen working with multiple OpenAPI 2.0 JSON files, identical
basePathvalues across files may cause issues in the generated code: We recommend ensuring that each OpenAPI 2.0 JSON file has a uniquebasePathvalue that matches the actual base path when the service is deployed. -
Unzip the downloaded Extend Codegen CLI template pack, navigate to the extracted folder, and run the
makecommand to generate the code.unzip accelbyte-unity-sdk-template-pack.zipcd accelbyte-unity-sdk-template-pack/make all \
CODEGEN_IMAGE_VERSION=0.0.28 \
PROJECT_PATH=/path/to/my-unity-project \
SPEC_PATH=/path/to/my-unity-project/spec \
PACKAGE_TYPE=plugin \
ADMIN_API_PATH=/admin/infoMake command parameters:
CODEGEN_IMAGE_VERSION: Docker image version from Docker Hub. Use the latest version listed (e.g.,0.0.28). Checkversion.txtin the template pack for the recommended version.PROJECT_PATH: Absolute path to your Unity project root (whereAssetsfolder is located). Must match the path from step 1.SPEC_PATH: Absolute path to thespecfolder containing your OpenAPI 2.0 JSON files. Must match the path from step 1.PACKAGE_TYPE: Choose one of two options:- module: Generates as a module within the existing AccelByte Unity SDK package.
- plugin (recommended): Generates as a standalone package named
com.AccelByte.SDK.Customin your project's parent directory.
ADMIN_API_PATH(optional): Separates admin/server endpoints from client endpoints:- If specified (e.g.,
/admin/), ServerAPI includes endpoints with this path prefix, ClientAPI includes all others. - If not specified, both ServerAPI and ClientAPI include all available endpoints.
- If specified (e.g.,
tipWhat happens during code generation:
- Docker pulls the
accelbyte/extend-codegen-cli:<version>image (if not already cached). - The CLI reads your OpenAPI 2.0 JSON files from
SPEC_PATH. - Jinja2 templates from the template pack are processed with your OpenAPI spec data.
- Generated C# code (
.csfiles) is written toPROJECT_PATH/../com.AccelByte.SDK.Custom/(forPACKAGE_TYPE=plugin). - The package structure includes:
Runtime/Api/- API client classesRuntime/Models/- Data modelspackage.json- Unity package manifestRuntime/AccelByte.Sdk.Custom.asmdef- Assembly definition
cautionBefore running the make command:
- Close Unity Editor before generating code to avoid file lock issues and assembly reload problems.
- If regenerating code, consider backing up any manual modifications to the generated package.
- When modifying or replacing the OpenAPI 2.0 JSON file, remove any leftover generated files to avoid compilation errors.
tip[OPTIONAL] Manually pulling the Docker image: While the
makecommand automatically pulls the Docker image, you can pre-download it to verify connectivity or cache it:docker pull accelbyte/extend-codegen-cli:0.0.28To check the version and verify the image:
docker run --rm accelbyte/extend-codegen-cli:0.0.28 infoExpected output:
version: 0.0.28
hash: 6b93fa76ad531938c02b1be7e0ab0958fad8c72d
glibc: 2.31
sub-packages:
accelbyte-codegen-ext-openapi2-legacy:
version: 0.0.28
description: AccelByte Code Generator [Open API 2.0 - Legacy]To see available commands:
docker run --rm accelbyte/extend-codegen-cli:0.0.28 --help -
Verify the generated package files.
After running the
makecommand, verify that the package was generated successfully:ls -la /path/to/com.AccelByte.SDK.Custom/Expected output (for
PACKAGE_TYPE=plugin):com.AccelByte.SDK.Custom/
|__ package.json
|__ Runtime/
|__ AccelByte.Sdk.Custom.asmdef
|__ Api/
| |__ Guild.cs
|__ Models/
|__ GuildModels.cstipKey files to check:
package.json: Unity package manifest with name, version, and dependenciesAccelByte.Sdk.Custom.asmdef: Assembly definition referencing the base AccelByte SDKApi/<ServiceName>.cs: API client classes (e.g.,Guild.csforguild.json)Models/<ServiceName>Models.cs: Data models for request/response structures
-
Add
com.accelbyte.unitysdk.customas a dependency inPackages/manifest.json.{
"dependencies": {
"com.accelbyte.unitysdk": "file:../com.AccelByte.SDK",
...
"com.accelbyte.unitysdk.custom": "file:../com.AccelByte.SDK.Custom"
}
}infoUnity will automatically reload the package when you reopen the Unity Editor or modify
manifest.json. You can verify the package is loaded by checking the Package Manager window (Window > Package Manager > In Project).
Integrate Extend Service Extension API into your Unity project
-
Include API from the
AccelByte SDKplugin.using AccelByte.Api;
using AccelByte.Core;
using AccelByte.Models; -
Call the API function.
noteThe proper and simpler way to call the Custom SDK function will be available in release 2026.2.
For the legacy version, it is required to create an extension class to access the generated custom SDK functionalities. The following snippet is the extension class example
/// <summary>
/// Extension class to add ServerGuild service to ServerApiClient
/// </summary>
public static class ServerApiClientCustomExtensions
{
/// <summary>
/// Prepare the temporary variable to return the actual custom SDK class
/// </summary>
private static ServerGuild serverGuildService;
/// <summary>
/// Get or create the ServerGuildService instance
/// </summary>
public static ServerGuild GetServerGuild(this ServerApiClient apiClient)
{
if (serverGuildService == null)
{
// Get dependencies from the ServerApiClient
var httpClient = new AccelByteHttpClient();
var clientConfig = AccelByteSDK.GetServerConfig();
var coroutineRunner = new CoroutineRunner();
// Create the API and wrapper
var guildApi = new ServerGuildApi(httpClient, clientConfig, apiClient.session);
serverGuildService = new ServerGuild(guildApi, apiClient.session, coroutineRunner);
}
return serverGuildService;
}
}Then you can call it as follows
// Get the Guild service using extension method
var serverGuildService = AccelByteSDK.GetServerRegistry().GetApi().GetServerGuild();
// Call the Generated API
serverGuildService.ServiceCreateOrUpdateGuildProgress();
// Call the API using the generated wrapper
string guildId = "any-guild-id";
Result<AccelByteGuildServiceGetGuildProgressResponse> result = null;
serverGuildService.ServiceGetGuildProgress(guildId, callback =>
{
if (callback.IsError)
{
UnityEngine.Debug.LogWarning($"Failed to get Guild progress [{callback.Error.Code}] {callback.Error.Message}");
}
else
{
// Do something with the callback result
result = callback;
}
});noteIn case you need to override the
ServerUrlof your custom service and/or thebasePath(e.g.,/guild), refer to the guide for Enabling environment switching for Unity.
Additional Resources
- Extend Codegen CLI GitHub Repository - Source code, documentation, and issue tracker
- Extend Codegen CLI Docker Hub - Available Docker image versions
- Jinja2 Documentation - Official Jinja2 template engine documentation
- OpenAPI 2.0 Specification - OpenAPI 2.0 (Swagger) specification reference
Understanding the Code Generation Process
The Extend Codegen CLI uses a template-based approach powered by Jinja2 to generate Unity SDK code:
- Input: OpenAPI 2.0 JSON file(s) describing your custom service API
- Processing: The CLI parses the spec using
OA2LegacyProcessorto extract endpoints, models, and parameters - Template Rendering: Jinja2 templates in
templates/sdk_customization/are populated with parsed data - Output: Complete Unity package with API classes, models, and Unity package system integration
Template Structure
The template pack generates code from these main templates:
Client-operations.j2→ Client API classesClient-wrapper.j2→ Client API wrapper classesGameServer-operations.j2→ Server API classesoperations-models.j2→ Model classes for request/response structurespackage.j2→ Unity package manifest (package.json)
File Naming Convention
Generated files use the OpenAPI JSON filename (converted to PascalCase):
| OpenAPI File | Generated API Class | Generated Models | Generated Wrapper |
|---|---|---|---|
guild.json | Guild.cs | GuildModels.cs | GuildWrapper.cs |
tournament.json | Tournament.cs | TournamentModels.cs | TournamentWrapper.cs |
For a deep dive into Jinja2 templates, custom filters, and advanced debugging techniques, see Extend Codegen CLI - Templates and Debugging.
Troubleshooting
Code generation fails with "Docker not found"
Symptom: make: docker: Command not found or similar error.
Solution:
- Verify Docker is installed:
docker --version - Ensure Docker daemon is running:
docker ps - Check user permissions:
docker run hello-world - If permission denied, add user to docker group:
sudo usermod -aG docker $USERand log out/in
Code generation fails with "Invalid OpenAPI specification"
Symptom: Codegen CLI reports validation errors or fails to parse the OpenAPI JSON file.
Solution:
- Validate your OpenAPI 2.0 spec using Swagger Editor
- Ensure the spec version is OpenAPI 2.0 (not 3.0+)
- Check for:
- Missing required fields (
swagger,info,paths) - Invalid JSON syntax (trailing commas, unquoted keys)
- Undefined schema references (
$refpointing to non-existent definitions)
- Missing required fields (
- If using Extend Service Extension, ensure the app is deployed and the OpenAPI spec is generated correctly
Generated code doesn't compile in Unity
Symptom: Compilation errors in Unity Console after adding the generated package.
Common causes and solutions:
-
Missing AccelByte SDK dependency:
- Error:
The type or namespace name 'AccelByte' could not be found - Solution: Ensure AccelByte Unity SDK is installed and listed in
Packages/manifest.jsonbefore the custom package
- Error:
-
Duplicate symbols or conflicting basePath:
- Error:
Type 'SomeModel' already existsor similar - Solution: Ensure each OpenAPI JSON file has a unique
basePathvalue
- Error:
-
Invalid C# identifiers:
- Error: Syntax errors in generated code
- Solution: Use lowercase alphabets (a-z) for OpenAPI JSON filenames. Avoid special characters, numbers, or uppercase letters.
-
Package not loaded:
- Error: Package doesn't appear in Unity Package Manager
- Solution: Check
package.jsonis valid JSON and the path inPackages/manifest.jsonis correct
-
Assembly definition errors:
- Error:
Assembly 'AccelByte.Sdk.Custom' has a reference to 'AccelByte.Sdk' which is not defined - Solution: Verify the base AccelByte SDK assembly definition is present and the custom package's
.asmdefreferences it correctly
- Error:
-
Outdated template pack:
- Error: Generated code uses deprecated SDK APIs
- Solution: Download the latest template pack from GitHub Releases
API calls return 404 or fail at runtime
Symptom: Generated API functions compile but fail when called from your game code.
Solution:
- Verify the custom service is deployed and accessible
- Check the
ServerUrlconfiguration in your Unity project settings - Ensure the
basePathin the OpenAPI spec matches the deployed service's base path - Enable SDK logging to inspect the actual HTTP requests being made
Multiple OpenAPI specs cause conflicts
Symptom: Compilation errors when using multiple custom services.
Solution:
- Ensure each OpenAPI JSON file has a unique
basePathvalue (e.g.,/guild,/tournament,/leaderboard) - Use unique filenames for each service (e.g.,
guild.json,tournament.json) - Verify no duplicate endpoint paths across different specs
- If conflicts persist, generate packages separately and use different package names
Regenerating code overwrites manual changes
Symptom: Custom modifications to generated code are lost when regenerating.
Solution:
- Don't modify generated code directly. Instead:
- Create wrapper classes that extend or compose the generated API classes
- Implement custom behavior in your game code, not in the package
- Use partial classes if the generated code supports them
- If you must modify generated code, maintain a separate patch file or version control branch
- Consider contributing improvements to the template pack if the generated code is insufficient
Unity Editor doesn't recognize the new package
Symptom: Package doesn't appear in Package Manager or code doesn't compile after adding to manifest.json.
Solution:
- Close and reopen Unity Editor to force package reload
- Check Unity Console for package loading errors
- Verify the package path in
manifest.jsonis correct (relative toPackagesfolder) - Ensure
package.jsonhas valid JSON syntax and required fields (name,version,displayName) - Try removing and re-adding the package in
manifest.json
Leftover files cause compilation errors
Symptom: Errors about duplicate types or missing references after modifying OpenAPI spec.
Solution:
- Delete the entire
com.AccelByte.SDK.Customfolder before regenerating - Remove the package from
Packages/manifest.jsontemporarily - Regenerate the code with the updated OpenAPI spec
- Re-add the package to
Packages/manifest.json - Restart Unity Editor
Docker image pull fails or is slow
Symptom: make command hangs or fails during Docker image download.
Solution:
- Check internet connectivity:
ping hub.docker.com - Verify Docker Hub is accessible:
docker pull hello-world - If behind a corporate proxy, configure Docker proxy settings
- Use a specific image version instead of
latestto avoid re-downloading - Pre-pull the image manually:
docker pull accelbyte/extend-codegen-cli:0.0.28
Need to debug the code generation process
Symptom: Generated code is incorrect or missing expected functionality.
Steps to debug:
- Inspect the OpenAPI spec: Ensure endpoints, models, and parameters are defined correctly
- Check the Jinja2 templates: Located in the template pack, these define how code is generated
- Review the Makefile: Shows the exact
docker runcommand and parameters passed to the CLI - Run with verbose logging: Add
VERBOSE=1to themakecommand to see detailed output - Use
--inspect verboseto explore the template environment: This powerful debugging tool reveals all available Jinja2 filters, functions, globals, and tests. See the Templates and Debugging guide for detailed usage. - Compare with working examples: Check the template pack's example specs and generated output
For additional support, refer to the Extend Codegen CLI GitHub repository or contact AccelByte support with:
- Your OpenAPI 2.0 JSON file
- The exact
makecommand used - Full error output from the code generation process
- Unity version and AccelByte SDK version