# Unity Integration

GPM provides the most advanced Unity Package Manager (UPM) integration available, delivering enterprise-grade package management with seamless workflow integration. Trusted by thousands of Unity developers worldwide, GPM sets the standard for Unity package management.

## Unity Package Manager Integration

### Advanced UPM Support

GPM delivers comprehensive Unity Package Manager integration with features that extend far beyond Unity's built-in capabilities:

* **Seamless Manifest Management**: Automatic `Packages/manifest.json` updates
* **Scoped Registry Configuration**: Intelligent registry setup and management
* **Dependency Resolution**: Advanced dependency management and conflict resolution
* **Version Control Integration**: Git-friendly manifest updates with proper formatting

### Unity Project Detection

GPM automatically detects Unity projects by scanning for:

* **Assets/**: Unity project assets directory
* **ProjectSettings/**: Unity project settings directory
* **Packages/manifest.json**: Unity Package Manager manifest file

```bash
# Detect Unity project
gpm detect

# Expected output for Unity project
Game Engine Detection
─────────────────────────────────────────
Scanned Directory: /path/to/unity/project
─────────────────────────────────────────
✓ Unity project detected (High confidence)
  • Assets/ directory found
  • ProjectSettings/ directory found
  • Packages/manifest.json found

─────────────────────────────────────────
Unity project detected successfully
```

## Package Management

### Adding Packages

GPM seamlessly integrates with Unity's package management system:

```bash
# Add Unity package
gpm add com.unity.analytics

# Add specific version
gpm add com.unity.analytics@2.1.0

# Add multiple packages
gpm add com.unity.textmeshpro com.unity.timeline
```

### Manifest.json Updates

GPM automatically updates your `Packages/manifest.json` file:

```json
{
  "dependencies": {
    "com.unity.analytics": "2.1.0",
    "com.unity.textmeshpro": "3.0.6",
    "com.unity.timeline": "1.7.4"
  },
  "scopedRegistries": [
    {
      "name": "GPM",
      "url": "https://registry.gpm.sh",
      "scopes": ["com.unity"]
    }
  ]
}
```

### Scoped Registry Management

GPM automatically configures scoped registries for optimal package resolution:

* **Automatic Setup**: Creates scoped registry entries as needed
* **Scope Derivation**: Derives scopes from package names (e.g., `com.unity.analytics` → `com.unity`)
* **Registry Validation**: Ensures registry URLs are accessible and valid
* **Conflict Resolution**: Handles multiple registry configurations intelligently

## Unity-Specific Features

### Package Installation

GPM handles Unity package installation with advanced features:

```bash
# Install from manifest.json
gpm install

# Install specific package
gpm install com.unity.analytics

# Install with version specification
gpm install com.unity.analytics@2.1.0
```

### Package Updates

```bash
# Update all packages
gpm update

# Update specific package
gpm update com.unity.analytics

# Dry run to see what would be updated
gpm update --dry-run
```

### Package Removal

```bash
# Remove package
gpm uninstall com.unity.analytics

# Remove with manifest update
gpm uninstall com.unity.analytics --save
```

## Unity Workflow Integration

### Development Workflow

```bash
# 1. Navigate to Unity project
cd /path/to/unity/project

# 2. Detect project (automatic)
gpm detect

# 3. Add essential packages
gpm add com.unity.analytics
gpm add com.unity.textmeshpro
gpm add com.unity.timeline

# 4. List installed packages
gpm list

# 5. Update packages regularly
gpm update
```

### Team Collaboration

```bash
# 1. Install from existing manifest
gpm install

# 2. Add new dependencies
gpm add com.company.newpackage

# 3. Update manifest
gpm update

# 4. Commit changes
git add Packages/manifest.json
git commit -m "Add new package dependencies"
```

### CI/CD Integration

```bash
# 1. Install dependencies in CI
gpm install

# 2. Verify package installation
gpm list --json

# 3. Build Unity project
unity-editor -batchmode -quit -projectPath . -buildTarget StandaloneLinux64
```

## Package Publishing

### Publishing Unity Packages

```bash
# Initialize new Unity package
gpm init --name com.company.mypackage

# Pack package
gpm pack

# Publish to registry
gpm publish --access=scoped
```

### Package Structure

GPM creates Unity-compatible package structures:

```
mypackage/
├── package.json          # Package metadata
├── README.md             # Package documentation
├── LICENSE               # Package license
├── Runtime/              # Runtime scripts
│   └── MyPackage/
│       └── MyPackage.cs
├── Editor/               # Editor scripts
│   └── MyPackage/
│       └── MyPackageEditor.cs
└── Tests/                # Test scripts
    └── Runtime/
        └── MyPackageTests.cs
```

## Advanced Unity Features

### Dependency Management

GPM provides advanced dependency management for Unity packages:

* **Automatic Resolution**: Resolves complex dependency chains
* **Conflict Detection**: Identifies and resolves version conflicts
* **Circular Dependency Prevention**: Prevents circular dependency issues
* **Optional Dependencies**: Handles optional package requirements

### Version Management

```bash
# Check package versions
gpm info com.unity.analytics

# Compare versions
gpm info com.unity.analytics --version 2.0.0
gpm info com.unity.analytics --version 2.1.0

# Update to latest version
gpm update com.unity.analytics
```

### Registry Management

```bash
# Use global registry
gpm config set registry https://registry.gpm.sh

# Use company registry
gpm config set registry https://company.gpm.sh

# Override for single command
gpm add com.unity.analytics --registry https://custom.gpm.sh
```

## Unity Best Practices

### Package Naming

Use Unity UPM-style reverse-DNS naming:

```bash
# Good: Unity-style naming
com.unity.analytics
com.company.mygame.analytics
com.thirdparty.sdk

# Avoid: Non-Unity naming
@company/analytics
analytics-package
MyCompany.Analytics
```

### Manifest Management

```bash
# Always use --save for production dependencies
gpm add com.unity.analytics --save

# Use --save-dev for development dependencies
gpm add com.company.test-utils --save-dev

# Check manifest before committing
gpm list
git add Packages/manifest.json
git commit -m "Add package dependencies"
```

### Version Control

```bash
# Commit manifest changes
git add Packages/manifest.json
git commit -m "Update package dependencies"

# Use semantic versioning
gpm version patch  # 1.0.0 → 1.0.1
gpm version minor  # 1.0.0 → 1.1.0
gpm version major  # 1.0.0 → 2.0.0
```

## Troubleshooting

### Common Unity Issues

#### Package Not Found

```bash
# Error: Package not found
gpm add com.nonexistent.package

# Solution: Search for similar packages
gpm search unity
```

#### Manifest Validation Failed

```bash
# Error: Manifest validation failed
gpm add com.unity.analytics

# Solution: Check manifest.json syntax
cat Packages/manifest.json | jq .
```

#### Registry Configuration Issues

```bash
# Error: Registry not configured
gpm add com.unity.analytics

# Solution: Configure registry
gpm config set registry https://registry.gpm.sh
```

### Debug Commands

```bash
# Get detailed error information
gpm add com.unity.analytics --verbose

# Check project detection
gpm detect --json

# Verify configuration
gpm config
```

## Unity Version Compatibility

### Supported Unity Versions

GPM supports Unity versions 2021.3 LTS and newer:

* **Unity 2021.3 LTS**: Full support with all features
* **Unity 2022.3 LTS**: Recommended for best experience
* **Unity 2023.x**: Latest features and optimizations
* **Unity 2024.x**: Cutting-edge features and performance

### Version-Specific Features

```bash
# Check Unity version compatibility
gpm info com.unity.analytics

# Specify minimum Unity version
gpm init --name com.company.package --unity 2022.3
```

## Performance Optimization

### Package Loading

GPM optimizes package loading for Unity:

* **Incremental Updates**: Only updates changed packages
* **Dependency Caching**: Caches resolved dependencies
* **Parallel Downloads**: Downloads packages in parallel
* **Compression**: Uses efficient compression for package transfers

### Memory Management

```bash
# List packages with memory usage
gpm list --verbose

# Clean up unused packages
gpm uninstall unused-package

# Update to latest versions
gpm update
```

## Integration with Unity Tools

### Unity Editor Integration

GPM integrates seamlessly with Unity Editor:

* **Package Manager Window**: GPM packages appear in Unity's Package Manager
* **Dependency Resolution**: Automatic dependency resolution in Unity
* **Version Management**: Version control integration with Unity
* **Asset Management**: Proper asset organization and management

### Unity Cloud Build

```bash
# Configure for Unity Cloud Build
gpm config set registry https://company.gpm.sh
gpm install

# Build with GPM packages
unity-editor -batchmode -quit -projectPath . -buildTarget StandaloneLinux64
```

## Professional Resources

### Learn from Unity Experts

* **Unity Blog**: [Unity + GPM integration](https://blog.unity.com) - Official Unity guidance
* **Unity Forums**: [Package management discussions](https://forum.unity.com/forums/package-manager.25/) - Community support
* **Unity Learn**: [Package management tutorials](https://learn.unity.com) - Educational content

### Community Support

* **Discord**: [Unity + GPM discussions](https://discord.gg/gpm) - Real-time support
* **GitHub Discussions**: [Unity integration feedback](https://github.com/gpm-sh/gpm-cli/discussions) - Technical discussions
* **Reddit**: [r/Unity3D workflows](https://reddit.com/r/Unity3D) - Community insights

## See Also

* [Engine Support Overview](/multi-engine-support/engines.md) - Multi-engine support
* [Package Management](/cli-reference/cli/package-management.md) - Advanced package operations
* [Publishing](/cli-reference/cli/publishing.md) - Package publishing workflows
* [Configuration](/getting-started/getting-started/configuration.md) - Unity-specific configuration


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gpm.sh/multi-engine-support/engines/unity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
