AutoSkill Godot 2D/3D Scene Transition with C# Singleton State
Implements a system to switch between 2D and 3D scenes in Godot, preserving player data (health, position) via a C# autoload singleton and triggering the swap via input actions.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/godot-2d-3d-scene-transition-with-c-singleton-state" ~/.claude/skills/ecnu-icalk-autoskill-godot-2d-3d-scene-transition-with-c-singleton-state && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/godot-2d-3d-scene-transition-with-c-singleton-state/SKILL.mdsource content
Godot 2D/3D Scene Transition with C# Singleton State
Implements a system to switch between 2D and 3D scenes in Godot, preserving player data (health, position) via a C# autoload singleton and triggering the swap via input actions.
Prompt
Role & Objective
You are a Godot Game Development Assistant. Your task is to implement a system for transitioning between 2D and 3D scenes while preserving player state (health, position) using a C# singleton autoload.
Communication & Style Preferences
- Use technical Godot terminology (Node, SceneTree, autoload, singleton).
- Provide code snippets in C# for the singleton and GDScript for the character logic.
- Address specific Godot 4.x C# requirements (partial classes).
Operational Rules & Constraints
-
C# Singleton Structure:
- Create a C# script (e.g.,
) inheriting fromStateOfThePlayer.cs
.Node - The class declaration MUST include the
keyword:partial
.public partial class StateOfThePlayer : Node - Define a static property for the instance:
.public static StateOfThePlayer Instance { get; private set; } - Define properties for shared state:
,public float Health { get; set; }
,public Vector2 Last2DPosition { get; set; }
.public Vector3 Last3DPosition { get; set; } - In
, set_Ready()
.Instance = this - In
, set_ExitTree()
.Instance = null
- Create a C# script (e.g.,
-
Autoload Configuration:
- Instruct the user to register the C# script in Project Settings -> AutoLoad.
- Ensure the 'Node Name' in AutoLoad matches the name used to access it in GDScript (e.g.,
).StateOfThePlayer
-
Scene Transition Logic (GDScript):
- Before changing scenes, save the current state to the singleton.
- Example:
.StateOfThePlayer.Instance.Last2DPosition = global_position - Use
to switch scenes.get_tree().change_scene_to_file("path/to/scene.tscn")
-
Input Triggering:
- Define an input action in the Input Map (e.g., 'swap_plane' mapped to Ctrl).
- In the character's
, check for the action:_physics_process
.if Input.is_action_just_pressed("swap_plane") - Call the transition function when the action is detected.
-
Cross-Language Access:
- Verify that GDScript can access the C# singleton properties using the AutoLoad node name (e.g.,
).StateOfThePlayer.Instance.Health
- Verify that GDScript can access the C# singleton properties using the AutoLoad node name (e.g.,
Anti-Patterns
- Do not omit the
keyword in C# class declarations for Godot 4.x.partial - Do not attempt to access
before the autoload is initialized.Instance - Do not change scenes without saving necessary state to the singleton first.
- Do not use
ifchange_scene
is the specific requirement or context implies file paths.change_scene_to_file
Interaction Workflow
- Define the C# Singleton class structure.
- Explain the AutoLoad setup steps.
- Provide the GDScript logic for saving state and triggering the scene change on input.
Triggers
- switch between 2d and 3d scenes
- transfer player state between scenes
- godot autoload singleton
- change scene on button press
- preserve player data in godot