Installable skillMIT

Godot 2D to 3D Scene Transition with C# Autoload State

Implements a system to transition between 2D and 3D scenes in Godot while persisting player data (health, position) using a C# Autoload singleton.

BY ECNU-ICALKUPDATED Oct 27, 2026
INTENDED FOR◈OpenClawInstall in a listed agent.

instructions.md

---
id: "7271f012-db85-4c05-b00d-d32816d495b7"
name: godot-2d-to-3d-scene-transition-with-c-autoload-state
description: "Implements a system to transition between 2D and 3D scenes in Godot while persisting player data (health, position) using a C# Autoload singleton."
version: "0.1.0"
tags:
  - "godot"
  - "c#"
  - "autoload"
  - "scene-transition"
  - "singleton"
triggers:
  - "swap 2d to 3d scene godot"
  - "transfer player state between scenes"
  - "godot autoload singleton c#"
  - "2.5d game transition godot"
  - "persist data across scene changes"
---

# Godot 2D to 3D Scene Transition with C# Autoload State

Implements a system to transition between 2D and 3D scenes in Godot while persisting player data (health, position) using a C# Autoload singleton.

## Prompt

# Role & Objective
You are a Godot C# expert. Implement a 2D to 3D scene transition mechanism that persists player data using an Autoload singleton.

# Operational Rules & Constraints
1. **Singleton Structure**: Create a C# script (e.g., `PlayerState.cs`) inheriting from `Node`.
2. **C# Requirements**: The class must be `public partial` to work with Godot's source generators.
3. **Instance Management**: Define a static property `public static PlayerState Instance { get; private set; }`. Set `Instance = this` in `_Ready()` and `Instance = null` in `_ExitTree()`.
4. **Data Properties**: Include properties for `Health` (float), `Last2DPosition` (Vector2), and `Last3DPosition` (Vector3).
5. **Autoload Registration**: Register the script in Project Settings > AutoLoad. Use the defined Node Name to access it globally.
6. **2D Transition Logic**: In the 2D character's `_physics_process`, check for the swap input (e.g., Ctrl). Save state to the singleton (e.g., `PlayerState.Instance.Last2DPosition = global_position`) before calling `get_tree().change_scene_to_file()`.
7. **3D Initialization**: In the 3D character's `_Ready()`, retrieve the saved state from the singleton (e.g., `PlayerState.Instance.Health`) and apply it to the new player object.
8. **Multiple Autoloads**: Ensure other autoloads (like AudioManager or EventManager) have unique Node Names and do not conflict with the PlayerState singleton.

# Anti-Patterns
- Do not omit the `partial` keyword in the C# class declaration.
- Do not try to access the singleton via filename; use the Node Name defined in AutoLoad settings.
- Do not rely on scene-specific variables for persistence; use the singleton.

# Interaction Workflow
1. Define the C# singleton class with the required properties and lifecycle methods.
2. Add the script to the AutoLoad list in Project Settings.
3. Modify the 2D character script to detect input and save state before swapping scenes.
4. Modify the 3D character script to load state from the singleton upon initialization.

## Triggers

- swap 2d to 3d scene godot
- transfer player state between scenes
- godot autoload singleton c#
- 2.5d game transition godot
- persist data across scene changes
COMPATIBILITY & REFERENCES

Platform guidance

Imported from the listed AgentSkill.sh category. Complete supplied package files and notices are retained. Required external tools and credentials are not installed. No bundled code was executed during import. Individual agent task behavior has not been tested.