docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Generate C# API from actions

    Input action assets allow you to generate a C# class from your action definitions, which allow you to refer to your actions in a type-safe manner from code.

    This removes the need to manually look up Actions and action maps using their names, and also provides an easy way to set up callbacks.

    Note

    This is an alternative workflow to project-wide actions, and provides a different way to access the actions defined in your action asset.

    To enable type-safe C# API generation:

    1. Select the action asset in the Project window.
    2. In the Inpsector window, enable the Generate C# Class option.
    3. Select Apply.

    MyPlayerControls Importer Settings

    You can optionally choose a path name, class name, and namespace for the generated script, or keep the default values.

    Once applied, the Input System creates a C# script containing API that matches the actions defined in the asset which you can access directly in code. The following example demonstrates this, assuming there is an action map named "gameplay" containing two actions, "use" and "move" defined in the action asset:

    Warning

    It looks like the sample you are looking for does not exist.

    Note

    To regenerate the .cs file, right-click the .inputactions asset in the Project Browser and select Reimpor.

    In This Article
    Back to top
    Copyright © 2026 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)