#Need some help about inputs

1 messages · Page 1 of 1 (latest)

olive tiger
#

I'm a French student and I'm trying to use unity for my school project. The goal is to make a VR drone flight simulator. We are 4 and my part is about using a radio command.

I'm trying to use the Input System package but when I'm trying to move my square to test my code I got an error message :
"InvalidOperationException while executing 'performed' callbacks of 'Gameplay/MoveRight[/Keyboard/d]'"

For the moment I just want to try to move my square to the right by using D. I think the problem is from my code I just followed a video that explains how to use the input package but my lack of experience in unity and C# don't allow me to get rid of my problem I tried to search on some Unity forum but nothing helped.

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

public class Deplacement : MonoBehaviour
{
        PlayerControls controls;

        Vector2 move;

    void Awake(){
        controls = new PlayerControls();
        controls.Gameplay.Grow.performed += ctx => Grow();
        controls.Gameplay.MoveRight.performed += ctx => move = ctx.ReadValue<Vector2>(); 
        controls.Gameplay.MoveRight.canceled += ctx => move = Vector2.zero; 

    }

    void Grow(){
        transform.localScale *= 1.1f;
    }

    void Update(){
        Vector2 m = new Vector2(-move.x, move.y) * Time.deltaTime;
        transform.Translate(m, Space.World);
    }

    void OnEnable(){
        controls.Gameplay.Enable();
    }

    void OnDisable(){
        controls.Gameplay.Disable();
    }

}

Even if the video is well-made, I still can't understand some details about his code.

Thanks in advance catto

(BTW if someone know how to fix the missing R in the search bar from the input action menu, I already change it but it keep come back)

#

"i will give the entire error message asap"

olive tiger
#
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputActionState.cs:2808)
UnityEngine.InputSystem.InputAction+CallbackContext.ReadValue[TValue] () (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Actions/InputAction.cs:1948)
Deplacement.<Awake>b__2_1 (UnityEngine.InputSystem.InputAction+CallbackContext ctx) (at Assets/Scripts/Deplacement.cs:15)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)

InvalidOperationException while executing 'performed' callbacks of 'Gameplay/MoveRight[/Keyboard/d]'
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)