agentsclimarketplace

Unity input system migration for networked player controller

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/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.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill unity-input-system-migration-for-networked-player-controller

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

4.2 KB, 869 tokens by cl100k_base, as published. Nobody here has run it

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., PlayerControls) derived from an Input Actions Asset.
  • Maintain the existing class structure (inheritance from DriveController or Shooting).
  • Do not invent new methods; use existing ones like SendNewInput, SendNitro, ClientShoot, etc.

Operational Rules & Constraints

  1. Input System Setup:

    • Instantiate the generated Input Actions class (e.g., playerControls = new PlayerControls();) in Awake().
    • Subscribe to performed and canceled events for actions like Accelerate, Steer, Brake, Nitro, and Shoot.
    • Enable actions in OnEnable() and disable them in OnDisable().
  2. State-Change Logic (Crucial):

    • Do NOT call SendNewInput directly inside the performed or canceled event callbacks.
    • Instead, use the event callbacks to update local state variables (e.g., currentAcceleration, currentSteering, currentBrake).
    • In FixedUpdate() (or Update()), compare the current state variables against their previous values (e.g., prevAcceleration).
    • Only call SendNewInput(motor, steering, handbrake) if any of the states have changed. This prevents spamming the network.
  3. Automatic Fire (PlayerShooting):

    • Use a boolean flag (e.g., isShooting) to track if the fire button is held down.
    • Set isShooting = true in the Shoot performed callback and false in canceled.
    • In Update(), check if (isShooting && shootBlock <= 0) to execute the shot logic repeatedly.
  4. Mouse Delta Reading:

    • To read Mouse X/Y axes, create actions in the Input Actions Asset bound to Mouse -> Delta -> X and Mouse -> Delta -> Y.
    • Subscribe to these actions and read the float values into a Vector2 variable (e.g., mouseDelta) during the performed callback.
    • Use this variable in Update() for camera rotation or look logic, then reset it to zero.
  5. 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, Input.GetKeyDown, or Input.GetAxis.
  • Do not call SendNewInput on every frame or every input event trigger.
  • Do not add GetComponent calls for CarController if the user specifies using base class/static access.
  • Do not remove the prevAcceleration / prevSteering comparison logic.

Interaction Workflow

  1. Initialize PlayerControls in Awake.
  2. Subscribe to input events to update local state variables.
  3. In FixedUpdate, check for state changes and invoke SendNewInput only if necessary.
  4. For shooting, use Update to poll the isShooting flag for continuous fire.

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.