Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How do I assign my Input Asset and Action Map to the new Player Input script?

Discussion in 'Scripting' started by fgbg, May 28, 2020.

  1. fgbg

    fgbg

    Joined:
    Dec 22, 2012
    Posts:
    53
    How do I assign my already-created input asset and action map to my Player Input script on my player? I made this in the gui and created the C# script from it via the button in the gui.

    This is about as far as I've been able to get:
    Code (CSharp):
    1.         GameObject player = new GameObject();
    2.         PlayerInput controls = player.AddComponent<PlayerInput>();
    3.         controls.actions.AddActionMap(...?...) //This is just an assumption due to the name I see in the Player input script
    I'm just not sure how to get a reference to my input asset (named Controls) or an action map in it (named PlayerControls). How do I achieve this?
     
  2. fgbg

    fgbg

    Joined:
    Dec 22, 2012
    Posts:
    53
    I needed to move my input assets under Resources folder and use Load I guess:
    Code (CSharp):
    1.         PlayerInput controls = tutorial.AddComponent<PlayerInput>();
    2.         controls.actions = Resources.Load<InputActionAsset>("Inputs/Controls");