docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputValue

    Wraps around values provided by input actions.

    Inheritance
    object
    InputValue
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    Syntax
    public class InputValue
    Remarks

    This is a wrapper around InputAction.CallbackContext chiefly for use with GameObject messages (i.e. SendMessage(string, object)). It exists so that action callback data can be represented as an object, can be reused, and shields the receiver from having to know about action callback specifics.

    Properties

    isPressed

    Check if the action button is pressed.

    Declaration
    public bool isPressed { get; }
    Property Value
    Type Description
    bool
    Remarks

    True if the button is activated over the button threshold. False otherwise The following example check if a button is pressed when receiving a PlayerInput message. The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly.

    Examples
    [RequireComponent(typeof(PlayerInput))] public class MyPlayerLogic : MonoBehaviour { // 'Fire' input action has been triggered. public void OnFire(InputValue value) { if (value.isPressed) FireWeapon(); } public void FireWeapon() { // Weapon firing code } }
    See Also
    pressPointOrDefault

    Methods

    Get()

    Read the current value as an object.

    Declaration
    public object Get()
    Returns
    Type Description
    object

    The current value in the form of a boxed object.

    Remarks

    This method allocates GC memory and will thus create garbage. If used during gameplay, it will lead to GC spikes.

    See Also
    InputAction

    Get<TValue>()

    Read the current value of the action.

    Declaration
    public TValue Get<TValue>() where TValue : struct
    Returns
    Type Description
    TValue

    The current value from the action cast to the specified type.

    Type Parameters
    Name Description
    TValue

    Type of value to read. This must correspond to the valueType of the action or, if it is a composite, by the valueType. The type depends on what type of controls the action is bound to. Common types are float and Vector2

    Remarks

    The following example shows how to read a value from a PlayerInput message. The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly.

    Examples
    using UnityEngine; using UnityEngine.InputSystem; [RequireComponent(typeof(PlayerInput))] public class MyPlayerLogic : MonoBehaviour { private Vector2 m_Move; // 'Move' input action has been triggered. public void OnMove(InputValue value) { // Read value from control. The type depends on what type of controls the action is bound to. m_Move = value.Get<Vector2>(); } public void Update() { // Update transform from m_Move } }
    Exceptions
    Type Condition
    InvalidOperationException

    The given type TValue does not match the value type expected by the control or binding composite.

    See Also
    ReadValue<TValue>()

    See Also

    InputAction

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • isPressed
    • Methods
      • Get()
      • Get<TValue>()
    • See Also
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)