Fix
Unity 6 Input System vs Input.GetAxis
Answer
In Unity 6 read input through the Input System package (UnityEngine.InputSystem). Do not call Input.GetAxis, Input.GetKey, or Input.GetButton. Those throw when the project is set to the new Input System only, which is the Unity 6 default for new projects.
- Unity 6.3 LTS (6000.3.x), APIs checked against 6000.6 docs on 2026-10-15
- Input System com.unity.inputsystem (Unity 6 new-project default)
Last verified 2026-10-15
Agents still call the old Input class inside a Unity 6 project. Input.GetAxis, Input.GetKey, and Input.GetButton throw when the project is set to the new Input System only, which is the Unity 6 default for new projects. The Unity 6 pack is written to stop that paste. It is pinned to Unity 6.3 LTS (6000.3.x), APIs checked against 6000.6 docs on 2026-10-15. The input package it names is com.unity.inputsystem (Unity 6 new-project default). Do not emit Unity 2022 or earlier APIs.
Read input through the Input System package (UnityEngine.InputSystem). Read buttons in Update. Write to a Rigidbody in FixedUpdate. The sample caches the body in Awake, sets a jump flag from Keyboard.current.spaceKey.wasPressedThisFrame in Update, and applies it in FixedUpdate. Null-check Keyboard.current and action references. They are null when the device is missing or the domain reloads.
Unity 6 renamed Rigidbody.velocity to Rigidbody.linearVelocity. The old name is obsolete. linearVelocity is a world-space vector in units per second. Do not assign linearVelocity every physics step. Use AddForce for ongoing motion and set linearVelocity only for an instant change such as a jump. The sample does that jump by writing body.linearVelocity with the existing x and z and a new y. Cache GetComponent<Rigidbody>() once. Do not call GetComponent, Find, or Camera.main inside Update.
Prefer a serialized reference over any Find call. Expose designer fields with [SerializeField] private. Do not make gameplay fields public just so the Inspector can see them. The done checklist says the Console shows no compile errors after the editor recompiles, no obsolete-API warnings were introduced (FindObjectOfType, velocity, Input.*), and you said whether Play Mode was actually tested.
Last verified 2026-10-15. doc-verified.
Unity 6 pack — Unity 6 C# rules that avoid the obsolete 2022 APIs.
doc-verified
Sample from the pack
The jump sample in the Unity 6 rules file.
using UnityEngine;
using UnityEngine.InputSystem;
public class Jumper : MonoBehaviour
{
[SerializeField] private float jumpSpeed = 6f;
private Rigidbody body;
private bool jumpPressed;
private void Awake()
{
body = GetComponent<Rigidbody>();
}
private void Update()
{
jumpPressed = Keyboard.current != null && Keyboard.current.spaceKey.wasPressedThisFrame;
}
private void FixedUpdate()
{
if (!jumpPressed) return;
body.linearVelocity = new Vector3(body.linearVelocity.x, jumpSpeed, body.linearVelocity.z);
jumpPressed = false;
}
}Sources in the pack
- unity.com/releases/unity-6/support
- docs.unity.com/en-us/engine/6000.0/manual/upgrade-guides/upgrade-guide-unity6
- docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/rigidbody/linearvelocity
- docs.unity.com/en-us/engine/6000.6/manual/scripting/fundamental-unity-types/instanceid-to-entityid-migration
Questions
- What should I use instead of Input.GetAxis in Unity 6?
- In Unity 6 read input through the Input System package (UnityEngine.InputSystem). Do not call Input.GetAxis, Input.GetKey, or Input.GetButton. Those throw when the project is set to the new Input System only, which is the Unity 6 default for new projects.
- Why does Input.GetKey throw in a new Unity 6 project?
- Input.GetAxis, Input.GetKey, and Input.GetButton throw when the project is set to the new Input System only, which is the Unity 6 default for new projects. Read input through the Input System package (UnityEngine.InputSystem).
- What replaces Rigidbody.velocity in Unity 6?
- Unity 6 renamed Rigidbody.velocity to Rigidbody.linearVelocity. The old name is obsolete. linearVelocity is a world-space vector in units per second. Do not assign linearVelocity every physics step. Use AddForce for ongoing motion and set linearVelocity only for an instant change such as a jump.
- When was this Unity 6 input rule last checked?
- Last verified 2026-10-15. doc-verified.