Hi, I’ve run into an issue with Input System - after reentering play mode input is not detected.
I use ScriptableObject to hold Input System - it is based on Unity Open Project 1 solution:
My SO code (Click is just LeftButton click):
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
namespace GameManager
{
[CreateAssetMenu(fileName = "InputReader", menuName = "Game/Input Reader")]
public class InputReader : ScriptableObject, InputManager.IPlayerActions
{
public event UnityAction<IClickable> ClickEvent = delegate {};
public InputManager _inputManager;
private void OnEnable()
{
if (_inputManager == null)
{
_inputManager = new InputManager();
_inputManager.Player.SetCallbacks(this);
}
_inputManager.Player.Enable();
}
public void OnClick(InputAction.CallbackContext context)
{
Debug.Log("Input System: OnClick");
if (context.phase == InputActionPhase.Performed)
{
var position = Mouse.current.position;
var ray = Camera.main.ScreenPointToRay(position.ReadValue());
RaycastHit hit;
Physics.Raycast(ray, out hit);
var clickable = hit.collider.GetComponent<IClickable>();
ClickEvent.Invoke(clickable);
}
}
Any ideas what am I missing? Or is it expected behaviour?
Unity Version: 2020.3.16.f1