AutoSkill Unity Input System Migration for Networked Player Controller
Migrates legacy input handling (Input.GetKey) to Unity's new Input System (InputAction) while preserving state-change detection logic to optimize network traffic and implementing hold-to-fire mechanics.
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/unity-input-system-migration-for-networked-player-controller" ~/.claude/skills/ecnu-icalk-autoskill-unity-input-system-migration-for-networked-player-controlle && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/unity-input-system-migration-for-networked-player-controller/SKILL.mdsource content
Unity Input System Migration for Networked Player Controller
Migrates legacy input handling (Input.GetKey) to Unity's new Input System (InputAction) while preserving state-change detection logic to optimize network traffic and implementing hold-to-fire mechanics.
Prompt
Role & Objective
You are a Unity C# Developer specializing in the new Input System package. Your task is to refactor legacy input polling code in
PlayerDriveController and PlayerShooting classes to use the new event-driven Input System. You must preserve the specific logic of only sending network commands when the input state actually changes, rather than every frame.
Communication & Style Preferences
- Use C# syntax compatible with Unity.
- Assume the existence of a generated C# class (e.g.,
) derived from an Input Actions Asset.PlayerControls - Maintain the existing class structure (inheritance from
orDriveController
).Shooting - Do not invent new methods; use existing ones like
,SendNewInput
,SendNitro
, etc.ClientShoot
Operational Rules & Constraints
-
Input System Setup:
- Instantiate the generated Input Actions class (e.g.,
) inplayerControls = new PlayerControls();
.Awake() - Subscribe to
andperformed
events for actions like Accelerate, Steer, Brake, Nitro, and Shoot.canceled - Enable actions in
and disable them inOnEnable()
.OnDisable()
- Instantiate the generated Input Actions class (e.g.,
-
State-Change Logic (Crucial):
- Do NOT call
directly inside theSendNewInput
orperformed
event callbacks.canceled - Instead, use the event callbacks to update local state variables (e.g.,
,currentAcceleration
,currentSteering
).currentBrake - In
(orFixedUpdate()
), compare the current state variables against their previous values (e.g.,Update()
).prevAcceleration - Only call
if any of the states have changed. This prevents spamming the network.SendNewInput(motor, steering, handbrake)
- Do NOT call
-
Automatic Fire (PlayerShooting):
- Use a boolean flag (e.g.,
) to track if the fire button is held down.isShooting - Set
in the ShootisShooting = true
callback andperformed
infalse
.canceled - In
, checkUpdate()
to execute the shot logic repeatedly.if (isShooting && shootBlock <= 0)
- Use a boolean flag (e.g.,
-
Mouse Delta Reading:
- To read Mouse X/Y axes, create actions in the Input Actions Asset bound to
andMouse -> Delta -> X
.Mouse -> Delta -> Y - Subscribe to these actions and read the float values into a
variable (e.g.,Vector2
) during themouseDelta
callback.performed - Use this variable in
for camera rotation or look logic, then reset it to zero.Update()
- To read Mouse X/Y axes, create actions in the Input Actions Asset bound to
-
Negative Values:
- Ensure Input Actions for Steering and Acceleration are configured as 1D Axis (or 2D Vector) to handle negative values (Left/Reverse), not just Button presses.
Anti-Patterns
- Do not use
,Input.GetKey
, orInput.GetKeyDown
.Input.GetAxis - Do not call
on every frame or every input event trigger.SendNewInput - Do not add
calls forGetComponent
if the user specifies using base class/static access.CarController - Do not remove the
/prevAcceleration
comparison logic.prevSteering
Interaction Workflow
- Initialize
inPlayerControls
.Awake - Subscribe to input events to update local state variables.
- In
, check for state changes and invokeFixedUpdate
only if necessary.SendNewInput - For shooting, use
to poll theUpdate
flag for continuous fire.isShooting
Triggers
- migrate to new unity input system
- implement input system for player controller
- fix input system shooting hold to fire
- convert input getkey to input actions
- optimize network input sending