# gpm detect

Detect game engine projects in the current or specified directory.

## Usage

```bash
gpm detect [directory] [flags]
```

## Arguments

* `[directory]` - Directory to scan for game engine projects (default: current directory)

## Flags

| Flag                   | Description                   | Default           |
| ---------------------- | ----------------------------- | ----------------- |
| `--project-dir <path>` | Project directory to scan     | Current directory |
| `--json`               | Output results in JSON format | `false`           |

## Description

The `gpm detect` command automatically detects game engine projects in the specified directory. GPM can identify Unity, Unreal Engine, Godot, and Cocos Creator projects based on their file structure and configuration files.

### Detection Criteria

* **Unity**: `Assets/`, `ProjectSettings/`, `Packages/manifest.json`
* **Unreal**: `*.uproject` files, `Content/`, `Config/`
* **Godot**: `project.godot` file, `.tscn` files
* **Cocos Creator**: `project.json`, `assets/` directory

### Confidence Levels

* **Maximum**: Very specific indicators (e.g., `.uproject` files)
* **High**: Multiple strong indicators
* **Medium**: Some indicators present
* **Low**: Weak or few indicators
* **None**: No indicators found

## Examples

### Basic Detection

```bash
# Detect in current directory
gpm detect

# Detect in specific directory
gpm detect /path/to/project

# Detect with project directory flag
gpm detect --project-dir /path/to/project
```

### JSON Output

```bash
# Get detection results in JSON
gpm detect --json

# Detect specific directory with JSON
gpm detect /path/to/project --json
```

## Output

### Human Format (Default)

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

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

### JSON Format (`--json`)

```json
{
  "success": true,
  "directory": "/path/to/project",
  "engines": [
    {
      "name": "unity",
      "confidence": "high",
      "indicators": [
        "Assets/ directory found",
        "ProjectSettings/ directory found",
        "Packages/manifest.json found"
      ]
    }
  ],
  "message": "Unity project detected successfully"
}
```

## Engine Detection Details

### Unity Detection

**High Confidence Indicators:**

* `Packages/manifest.json` file
* `Assets/` directory
* `ProjectSettings/` directory

**Medium Confidence Indicators:**

* `Library/` directory
* `Logs/` directory
* `Temp/` directory

**Low Confidence Indicators:**

* `.unity` files
* `.cs` files in root

### Unreal Engine Detection

**High Confidence Indicators:**

* `*.uproject` files
* `Content/` directory
* `Config/` directory

**Medium Confidence Indicators:**

* `Source/` directory
* `Plugins/` directory
* `.uplugin` files

**Low Confidence Indicators:**

* `.uasset` files
* `.umap` files

### Godot Detection

**High Confidence Indicators:**

* `project.godot` file
* `.tscn` files
* `.cs` files

**Medium Confidence Indicators:**

* `addons/` directory
* `.gd` files
* `.tres` files

**Low Confidence Indicators:**

* `.import` files
* `.tmp` files

### Cocos Creator Detection

**High Confidence Indicators:**

* `project.json` file
* `assets/` directory
* `settings/` directory

**Medium Confidence Indicators:**

* `build/` directory
* `library/` directory
* `.meta` files

**Low Confidence Indicators:**

* `.cc` files
* `.js` files

## Multiple Engine Detection

### Multiple Projects

```bash
# Detect multiple projects
gpm detect /path/to/projects

# Output shows all detected engines
```

```
Game Engine Detection
─────────────────────────────────────────
Scanned Directory: /path/to/projects
─────────────────────────────────────────
✓ Unity project detected (High confidence)
  • Assets/ directory found
  • ProjectSettings/ directory found
  • Packages/manifest.json found

✓ Godot project detected (High confidence)
  • project.godot file found
  • .tscn files found

─────────────────────────────────────────
2 projects detected successfully
```

### Nested Projects

```bash
# Detect nested projects
gpm detect /path/to/workspace

# Recursively scans subdirectories
```

## Error Handling

### Common Scenarios

* **No projects found**: `No game engine projects detected`
* **Directory not found**: `Directory not found: /path/to/project`
* **Permission denied**: `Permission denied: cannot read directory`
* **Invalid directory**: `Invalid directory: not a directory`

### Troubleshooting

1. **No projects found**: Check directory structure and file presence
2. **Directory not found**: Verify directory path exists
3. **Permission denied**: Check directory permissions
4. **Invalid directory**: Ensure path points to a directory

## Use Cases

### Project Discovery

```bash
# Discover projects in workspace
gpm detect /path/to/workspace

# Find Unity projects
gpm detect /path/to/workspace | grep -i unity
```

### CI/CD Integration

```bash
# Detect projects in CI
gpm detect --json > detection-results.json

# Process detection results
gpm detect --json | jq '.engines[] | .name'
```

### Development Workflow

```bash
# Check current project
gpm detect

# Verify project type
gpm detect --json | jq '.engines[0].name'
```

## Best Practices

### Project Organization

```bash
# Organize projects by engine
mkdir -p /workspace/unity-projects
mkdir -p /workspace/godot-projects
mkdir -p /workspace/unreal-projects

# Detect each engine type
gpm detect /workspace/unity-projects
gpm detect /workspace/godot-projects
gpm detect /workspace/unreal-projects
```

### Detection Validation

```bash
# Always verify detection results
gpm detect --json | jq '.engines[0].confidence'

# Check for specific engine
gpm detect --json | jq '.engines[] | select(.name == "unity")'
```

### Directory Structure

```bash
# Use clear project structure
/workspace/
├── unity-project/
│   ├── Assets/
│   ├── ProjectSettings/
│   └── Packages/
├── godot-project/
│   ├── project.godot
│   └── scenes/
└── unreal-project/
    ├── Project.uproject
    └── Content/
```

## Integration with Other Commands

### Package Management

```bash
# Detect project first
gpm detect

# Install packages based on detected engine
gpm install com.unity.analytics
```

### Project Initialization

```bash
# Detect existing project
gpm detect

# Initialize new package in project
gpm init --name com.company.mypackage
```

## Related Commands

* [`gpm add`](/cli-reference/cli/package-management/add.md) - Add packages to project
* [`gpm install`](/cli-reference/cli/package-management/install.md) - Install packages
* [`gpm init`](/cli-reference/cli/project/init.md) - Initialize new package

## See Also

* [Project Management](/cli-reference/cli/project.md)
* [Engine Support](/multi-engine-support/engines.md)
* [Multi-Engine Support](https://github.com/gpm-sh/docs/blob/main/engines/auto-detection.md)


---

# 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/cli-reference/cli/project/detect.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.
