Search Unity

Question Error CS7036

Discussion in 'Input System' started by ChamberGames, Dec 5, 2022.

  1. ChamberGames

    ChamberGames

    Joined:
    Mar 30, 2022
    Posts:
    10
    I am currently trying to get controller rumble to work in my game. I have downloaded a package with a script that when the left or right trigger is pressed the controller vibrates.

    Code (CSharp):
    1. using UnityEngine;
    2. using XInputDotNetPure; // Required in C#
    3.  
    4. public class XInputTestCS4 : MonoBehaviour
    5. {
    6.     bool playerIndexSet = false;
    7.     PlayerIndex playerIndex;
    8.     GamePadState state;
    9.     GamePadState prevState;
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         // No need to initialize anything for the plugin
    15.     }
    16.  
    17.     void FixedUpdate()
    18.     {
    19.         // SetVibration should be sent in a slower rate.
    20.         // Set vibration according to triggers
    21.         GamePad.SetVibration(playerIndex, state.Triggers.Left, state.Triggers.Right); // The line of interest
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         // Find a PlayerIndex, for a single player game
    28.         // Will find the first controller that is connected ans use it
    29.         if (!playerIndexSet || !prevState.IsConnected)
    30.         {
    31.             for (int i = 0; i < 4; ++i)
    32.             {
    33.                 PlayerIndex testPlayerIndex = (PlayerIndex)i;
    34.                 GamePadState testState = GamePad.GetState(testPlayerIndex);
    35.                 if (testState.IsConnected)
    36.                 {
    37.                     Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
    38.                     playerIndex = testPlayerIndex;
    39.                     playerIndexSet = true;
    40.                 }
    41.             }
    42.         }
    43.  
    44.         prevState = state;
    45.         state = GamePad.GetState(playerIndex);
    46.     }
    47. }
    Changed Code

    Code (CSharp):
    1. {
    2.         // SetVibration should be sent in a slower rate.
    3.         // Set vibration according to triggers
    4.         GamePad.SetVibration(playerIndex, state.Triggers.Right); //The line of interest
    5.     }
    As you can see, I have removed the left trigger vibration and I get
    error CS7036: There is no argument that corresponds to the required formal parameter 'rightMotor of'GamePad.SetVibration(PlayerIndex, float, float)'

    Can someone help navigate through the jargon to fix this problem.
     
  2. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    Hey @ChamberGames. I am pretty new to input system but honestly I don't think your issue is input system related. It might just be the problem with method signature or rather how you call it.

    If you using VisualStudio or have properly configured VSCode editor CTRL click (or CMD click if on mac) to step into the method. I suspect method takes 3 arguments and you are calling it with 2.

    If that's the case you could try
    Code (CSharp):
    1. GamePad.SetVibration(playerIndex, null, state.Triggers.Right);
    That would ensure you are calling it as it was defined in the example.
     
  3. ChamberGames

    ChamberGames

    Joined:
    Mar 30, 2022
    Posts:
    10
    I inserted the code but now I am getting
    error CS1503: Argument 2: cannot convert from '<null>' to 'float'
     
  4. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    92
    Well... Following the message I would suggest replacing null with 0 then.
    Code (CSharp):
    1. GamePad.SetVibration(playerIndex, 0, state.Triggers.Right);