Hi
Going nuts///
Summary:
Error with the new input system
MissingMethodException: Method 'CameraController.OnLook' not found.
System.RuntimeType.InvokeMember (System.String name, System.Reflection.BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) (at <321eb2db7c6d43ea8fc39b54eaca3452>:0)
UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) (at <adbae017f0374fce9921b97a33a4e8ca>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
I have been making some progress with this but am now going around in circles
Aim:
I want to be able to rotate the camera across 360 by either using a phone touchscreen or the right mouse button when testing in unity editor
If I am using a phone, i want to be able to tap on a button to select it (only action) or use the left mouse button when testing in the editor
So far i have set up inputaction PlayerControls
I then automatically created the script
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.11.2
// from Assets/MCAssets/input system/PlayerControls.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public partial class @PlayerControls: IInputActionCollection2, IDisposable
{
public InputActionAsset asset { get; }
public @PlayerControls()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""PlayerControls"",
""maps"": [
{
""name"": ""PlayerControlMap"",
""id"": ""b6b4a229-e1ba-43c0-9e2e-e19adb14d6b3"",
""actions"": [
{
""name"": ""Look"",
""type"": ""Value"",
""id"": ""643f36fd-daa9-490f-a540-9d345965e000"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""RightClick"",
""type"": ""Button"",
""id"": ""57416837-2db0-4e11-a02f-1014fb7c3dce"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Select"",
""type"": ""Button"",
""id"": ""f52f8c7a-7496-448e-8aa9-1b600b1b24eb"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
{
""name"": """",
""id"": ""bb18b4c4-f56e-4d31-8a10-3dec46ceca6e"",
""path"": ""<Touchscreen>/primaryTouch/delta"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f57942de-a4bd-4733-ad3d-705dee3016ff"",
""path"": ""<Mouse>/delta"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""36214987-6791-4980-bc3a-c8310439045b"",
""path"": ""<Mouse>/rightButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""RightClick"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""8d0c3203-5bac-49bc-bfb8-143b3309b76d"",
""path"": ""<Touchscreen>/primaryTouch/tap"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Select"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""63b6d328-71e1-48c2-915b-34a378f4e975"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Select"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": []
}");
// PlayerControlMap
m_PlayerControlMap = asset.FindActionMap("PlayerControlMap", throwIfNotFound: true);
m_PlayerControlMap_Look = m_PlayerControlMap.FindAction("Look", throwIfNotFound: true);
m_PlayerControlMap_RightClick = m_PlayerControlMap.FindAction("RightClick", throwIfNotFound: true);
m_PlayerControlMap_Select = m_PlayerControlMap.FindAction("Select", throwIfNotFound: true);
}
~@PlayerControls()
{
UnityEngine.Debug.Assert(!m_PlayerControlMap.enabled, "This will cause a leak and performance issues, PlayerControls.PlayerControlMap.Disable() has not been called.");
}
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();
}
public IEnumerable<InputBinding> bindings => asset.bindings;
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
}
// PlayerControlMap
private readonly InputActionMap m_PlayerControlMap;
private List<IPlayerControlMapActions> m_PlayerControlMapActionsCallbackInterfaces = new List<IPlayerControlMapActions>();
private readonly InputAction m_PlayerControlMap_Look;
private readonly InputAction m_PlayerControlMap_RightClick;
private readonly InputAction m_PlayerControlMap_Select;
public struct PlayerControlMapActions
{
private @PlayerControls m_Wrapper;
public PlayerControlMapActions(@PlayerControls wrapper) { m_Wrapper = wrapper; }
public InputAction @Look => m_Wrapper.m_PlayerControlMap_Look;
public InputAction @RightClick => m_Wrapper.m_PlayerControlMap_RightClick;
public InputAction @Select => m_Wrapper.m_PlayerControlMap_Select;
public InputActionMap Get() { return m_Wrapper.m_PlayerControlMap; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(PlayerControlMapActions set) { return set.Get(); }
public void AddCallbacks(IPlayerControlMapActions instance)
{
if (instance == null || m_Wrapper.m_PlayerControlMapActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_PlayerControlMapActionsCallbackInterfaces.Add(instance);
@Look.started += instance.OnLook;
@Look.performed += instance.OnLook;
@Look.canceled += instance.OnLook;
@RightClick.started += instance.OnRightClick;
@RightClick.performed += instance.OnRightClick;
@RightClick.canceled += instance.OnRightClick;
@Select.started += instance.OnSelect;
@Select.performed += instance.OnSelect;
@Select.canceled += instance.OnSelect;
}
private void UnregisterCallbacks(IPlayerControlMapActions instance)
{
@Look.started -= instance.OnLook;
@Look.performed -= instance.OnLook;
@Look.canceled -= instance.OnLook;
@RightClick.started -= instance.OnRightClick;
@RightClick.performed -= instance.OnRightClick;
@RightClick.canceled -= instance.OnRightClick;
@Select.started -= instance.OnSelect;
@Select.performed -= instance.OnSelect;
@Select.canceled -= instance.OnSelect;
}
public void RemoveCallbacks(IPlayerControlMapActions instance)
{
if (m_Wrapper.m_PlayerControlMapActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IPlayerControlMapActions instance)
{
foreach (var item in m_Wrapper.m_PlayerControlMapActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_PlayerControlMapActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public PlayerControlMapActions @PlayerControlMap => new PlayerControlMapActions(this);
public interface IPlayerControlMapActions
{
void OnLook(InputAction.CallbackContext context);
void OnRightClick(InputAction.CallbackContext context);
void OnSelect(InputAction.CallbackContext context);
}
}
I then have my cameracontroller script:
using UnityEngine;
using UnityEngine.InputSystem;
public class CameraController : MonoBehaviour
{
private PlayerControls inputActions;
private InputAction lookAction;
private InputAction rightClickAction;
private InputAction selectAction;
public float lookSpeed = 1f;
public bool invertVertical = false;
public bool invertHorizontal = false;
private float verticalRotation = 0f;
public float upperLimit = 80f;
public float lowerLimit = -80f;
private bool isRightMouseButtonPressed = false;
private void Awake()
{
inputActions = new PlayerControls(); // Make sure PlayerControls class is correctly generated
}
private void OnEnable()
{
// Enable the action map
inputActions.PlayerControlMap.Enable();
// Get the actions
lookAction = inputActions.PlayerControlMap.Look;
rightClickAction = inputActions.PlayerControlMap.RightClick;
selectAction = inputActions.PlayerControlMap.Select;
// Ensure callbacks are correctly hooked
lookAction.performed += OnLook; // Correctly subscribing
rightClickAction.started += OnRightClickStarted;
rightClickAction.canceled += OnRightClickCanceled;
selectAction.performed += OnSelect;
}
private void OnDisable()
{
// Disable the action map
inputActions.PlayerControlMap.Disable();
// Unsubscribe from the actions
lookAction.performed -= OnLook;
rightClickAction.started -= OnRightClickStarted;
rightClickAction.canceled -= OnRightClickCanceled;
selectAction.performed -= OnSelect;
}
// Ensure this method signature is exactly what Unity expects for the input action callback
public void OnLook(InputAction.CallbackContext context)
{
if (!isRightMouseButtonPressed) return;
Vector2 lookInput = context.ReadValue<Vector2>(); // Get input from Look action
float horizontalInput = invertHorizontal ? -lookInput.x : lookInput.x;
float verticalInput = invertVertical ? -lookInput.y : lookInput.y;
// Apply camera rotation
transform.Rotate(Vector3.up, horizontalInput * lookSpeed);
verticalRotation -= verticalInput * lookSpeed;
verticalRotation = Mathf.Clamp(verticalRotation, lowerLimit, upperLimit);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, Camera.main.transform.localRotation.eulerAngles.y, 0);
}
public void OnRightClickStarted(InputAction.CallbackContext context)
{
isRightMouseButtonPressed = true; // Start camera movement when right-click is pressed
}
public void OnRightClickCanceled(InputAction.CallbackContext context)
{
isRightMouseButtonPressed = false; // Stop camera movement when right-click is released
}
private void OnSelect(InputAction.CallbackContext context)
{
Debug.Log("Object Selected");
}
}
Which i have attached to my camera
The camera rotates as i want with the right mouse button and i register a click with the left in unity editor
However i also get this error and i have absolutely no idea how to fix:
MissingMethodException: Method 'CameraController.OnLook' not found.
System.RuntimeType.InvokeMember (System.String name, System.Reflection.BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) (at <321eb2db7c6d43ea8fc39b54eaca3452>:0)
UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) (at <adbae017f0374fce9921b97a33a4e8ca>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
Please help if you can
thanks

