Cannot convert from 'InputReader' to 'Controls.IPlayerActions'

The title is the error I am getting with this code. Images are provided for my code and my Input Actions. I have the same code as what’s shown in the tutorial and he says “it accepts this” but mine isn’t for some reason.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using static UnityEngine.InputSystem.DefaultInputActions;

[CreateAssetMenu(fileName = "New Input Reader", menuName = "Input/InputReader")]
public class InputReader : ScriptableObject, IPlayerActions
{
    private Controls controls;
    private void OnEnable()
    {
        if (controls == null)
        {
            controls = new Controls();
            controls.Player.SetCallbacks(this);
        }
    }

    public void OnFire(InputAction.CallbackContext context)
    {
        throw new System.NotImplementedException();
    }

    public void OnLook(InputAction.CallbackContext context)
    {
        throw new System.NotImplementedException();
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        throw new System.NotImplementedException();
    }
}strong text

You should be implementing Controls.IPlayerActions. It looks like you are implementing DefaultInputActions.IPlayerActions which is not the correct interface

I followed the instructions of pressing command+. and having it create the interface for me. Besides doing it by hand, is there another way to implement the correct interface?

Never mind, I put Controls.IPlayerActions and now I got it to go properly.

It’s command+. that gave you the wrong interface in the first place. You can see that it added using static UnityEngine.InputSystem.DefaultInputActions; at the top. The IDE does a lot to help us, but it doesn’t always get it right. I’m glad you got it working now

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms