AutoSkill unity_ml_agents_multi_instance_2d_setup
Develop top-down 2D Unity ML-Agents environments with WASD heuristic control and Ray Perception Sensor 2D, ensuring robust instance isolation for concurrent multi-area training.
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_GLM4.7/unity_ml_agents_multi_instance_2d_setup" ~/.claude/skills/ecnu-icalk-autoskill-unity-ml-agents-multi-instance-2d-setup && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/unity_ml_agents_multi_instance_2d_setup/SKILL.mdsource content
unity_ml_agents_multi_instance_2d_setup
Develop top-down 2D Unity ML-Agents environments with WASD heuristic control and Ray Perception Sensor 2D, ensuring robust instance isolation for concurrent multi-area training.
Prompt
Role & Objective
Act as a Unity ML-Agents expert. Develop a top-down 2D game where a circle character moves via WASD to eat food. The environment must be architected to support concurrent training by duplicating the TrainingArea multiple times without state conflicts.
Core Mechanics & ML-Agents Integration
- Movement: Implement character movement using WASD via Transform manipulation (no Rigidbody) to control the agent.
- Sensors: Configure Ray Perception Sensor 2D to detect objects tagged "Food" and "Wall".
- Heuristics: Implement
mapping keyboard input (Horizontal/Vertical) to agent actions.public override void Heuristic(in ActionBuffers actionsOut) - Game Loop:
- Spawn a specific number of food items (e.g., 10) per episode within a set distance of the player.
- Enforce a maximum episode time (e.g., 20 seconds).
- Spawn the player at a random position in the area.
- Award a reward (+1) when the player eats food.
Instance Isolation & Architecture (Crucial for Multi-Training)
To ensure multiple TrainingArea instances operate independently:
- State Isolation: Ensure all state lists (e.g.,
) are instance-specific (non-static) and not shared between clones.foodInstances - Coordinate Space: Use World Space (
) for physics calculations (e.g.,transform.position
) and interaction checks to ensure accuracy regardless of the TrainingArea's scene position. Do not rely solely onPhysics2D.OverlapCircle
for global interactions.localPosition - Parenting: Ensure spawned objects (food, agents) are correctly parented to the specific TrainingArea transform.
- Ownership Verification: When agents interact with objects, verify that the target object belongs to the current agent's specific TrainingArea instance.
Code Safety & Constraints
- Safe Modification: When resetting or modifying GameObject lists (e.g., replacing eaten food), use a
loop with index access instead offor
to safely replace null references or modify the collection during iteration.foreach - Latest Version: Use the latest ML-Agents version.
Anti-Patterns
- Do not use
lists for instance-specific data.static - Do not use
loops when modifying the collection being iterated over.foreach - Do not use Rigidbody for movement in this specific 2D setup.
- Do not mix local and world space coordinates arbitrarily in physics checks.
Triggers
- Unity ML-Agents multiple training areas
- Create a Unity ML Agents 2D game
- Unity game with Ray Perception Sensor 2D
- independent training instances
- Unity heuristic control WASD