Hello,
My problem is, that I don’t know, how I can assign the input action asset, called “Controler” in this case, to the game object player/its script.
This is the Player script:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControl : MonoBehaviour
{
public Controler controls;
void awake()
{
controls.Player.Move.performed += ctx => Move();
}
void Move()
{
Debug.Log("Player wants to move");
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
}
This is the script automatically generated from the input action asset:
// GENERATED AUTOMATICALLY FROM 'Assets/Controler.inputactions'
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class @Controler : IInputActionCollection, IDisposable
{
public InputActionAsset asset { get; }
public @Controler()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""Controler"",
""maps"": [
{
""name"": ""Player"",
""id"": ""732573cb-85f0-420c-a151-0ac0e11d16f8"",
""actions"": [
{
""name"": ""Move"",
""type"": ""PassThrough"",
""id"": ""4782f878-d69a-4554-b232-6b314ee5e79a"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """"
}
],
""bindings"": [
{
""name"": ""Axis"",
""id"": ""2e342f8d-00bb-4654-a6fd-3219975f18c5"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""6043f4fe-b046-4290-a4e7-1872a688facc"",
""path"": ""<Gamepad>/leftStick/up"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""ffc33f9e-47ad-4a29-9ab8-5101f323b22f"",
""path"": ""<Gamepad>/leftStick/down"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""06b7d20c-32e0-4c8d-873b-3fe9d1143d89"",
""path"": ""<Gamepad>/leftStick/left"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""052f6b4f-b4cd-4125-bfa5-43fffbe2484d"",
""path"": ""<Gamepad>/leftStick/right"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
}
]
}
],
""controlSchemes"": []
}");
// Player
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Move = m_Player.FindAction("Move", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
// Player
private readonly InputActionMap m_Player;
private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Move;
public struct PlayerActions
{
private @Controler m_Wrapper;
public PlayerActions(@Controler wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Player_Move;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
public void SetCallbacks(IPlayerActions instance)
{
if (m_Wrapper.m_PlayerActionsCallbackInterface != null)
{
@Move.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
@Move.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
@Move.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
}
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
}
}
}
public PlayerActions @Player => new PlayerActions(this);
public interface IPlayerActions
{
void OnMove(InputAction.CallbackContext context);
}
}
In unity, there should be the possibility to assign the input action asset, but there isn’t.
Please Help!