Skip to content

Feature request: Add cloneFromTemplate option to UnityEditor.createProject #12

@MtMath

Description

@MtMath

Description

Currently, the createProject function in UnityEditor allows creating new Unity projects programmatically, but it doesn't support creating projects from templates like the "URP template" or other built-in and custom templates. Unity has an undocumented feature to create projects from templates that would be valuable to expose through this library.

Proposed Solution

Enhance the createProject function to add support for template-based project creation by:

  1. Adding a new optional parameter template to the createProject function
  2. Implementing the logic to detect available templates (both built-in and custom)
  3. Supporting creation from these templates via command-line arguments

Technical Details

Unity implements templates as packages in specific locations:

  • Built-in templates are stored in [Unity Editor Path]/Editor/Data/Resources/PackageManager/ProjectTemplates on Windows
  • On macOS, they're in /Applications/Unity/Hub/Editor/[VERSION]/Unity.app/Contents/Resources/PackageManager/ProjectTemplates
  • Custom templates can be created and placed in these directories

When a template is selected in Unity Hub, it reads the template package (usually a .tgz file), extracts it, and uses its content as a base for the new project. This includes package dependencies, initial assets, and project settings.

Implementation approach

  1. Add a way to list available templates (through a new method like getAvailableTemplates())
  2. Enhance createProject to accept template name/path as an optional parameter
  3. Implement the command-line command that uses the undocumented template feature

Example Usage

// Create a project using the URP template
const projectInfo: ProjectInfo = {
  projectPath: "/path/to/new/project",
  editorVersion: "2022.3.15f1",
  template: "com.unity.template.universal" // or "URP" as a friendly name
};

await UnityEditor.createProject(projectInfo);

// Alternatively, list available templates first
const templates = await UnityEditor.getAvailableTemplates("2022.3.15f1");
console.log(templates); // Would return something like { "URP": "com.unity.template.universal", ... }

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions