Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How do I fix Error CS1061

Discussion in 'Input System' started by TrexMatrix, Sep 3, 2023.

  1. TrexMatrix

    TrexMatrix

    Joined:
    Aug 8, 2023
    Posts:
    39
    I was coding and got this error.
    Assets\Scripts\InputHandler.cs(74,36): error CS1061: 'PlayerControls' does not contain a definition for 'PlayerActions' and no accessible extension method 'PlayerActions' accepting a first argument of type 'PlayerControls' could be found (are you missing a using directive or an assembly reference?)

    Script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace HR
    6. {
    7.     public class InputHandler : MonoBehaviour
    8.     {
    9.         public float horizontal;
    10.         public float vertical;
    11.         public float moveAmount;
    12.         public float mouseX;
    13.         public float mouseY;
    14.  
    15.         public bool b_Input;
    16.         public bool rollFlag;
    17.  
    18.         PlayerControls inputActions;
    19.         CameraHandler cameraHandler;
    20.  
    21.         Vector2 movementInput;
    22.         Vector2 cameraInput;
    23.  
    24.         private void Awake()
    25.         {
    26.             cameraHandler = CameraHandler.singleton;
    27.         }
    28.  
    29.         private void FixedUpdate()
    30.         {
    31.             float delta = Time.fixedDeltaTime;
    32.  
    33.             if (cameraHandler != null)
    34.             {
    35.                 cameraHandler.FollowTarget(delta);
    36.                 cameraHandler.HandleCameraRotation(delta, mouseX, mouseY);
    37.             }
    38.         }
    39.  
    40.         public void OnEnable()
    41.         {
    42.             if (inputActions == null)
    43.             {
    44.                 inputActions = new PlayerControls();
    45.                 inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
    46.                 inputActions.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();
    47.             }
    48.  
    49.             inputActions.Enable();
    50.         }
    51.  
    52.         private void OnDisable()
    53.         {
    54.             inputActions.Disable();
    55.         }
    56.  
    57.         public void TickInput(float delta)
    58.         {
    59.             MoveInput(delta);
    60.             HandleRollInput(delta);
    61.         }
    62.  
    63.         private void MoveInput(float delta)
    64.         {
    65.             horizontal = movementInput.x;
    66.             vertical = movementInput.y;
    67.             moveAmount = Mathf.Clamp01(Mathf.Abs(horizontal) + Mathf.Abs(vertical));
    68.             mouseX = cameraInput.x;
    69.             mouseY = cameraInput.y;
    70.         }
    71.  
    72.         private void HandleRollInput(float delta)
    73.         {
    74.             b_Input = inputActions.PlayerActions.Roll.phase == UnityEngine.InputSystem.InputActionPhase.Started;
    75.  
    76.             if (b_Input)
    77.             {
    78.                 rollFlag = true;
    79.             }
    80.         }
    81.     }
    82. }
    83.  
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    854
    Did you not mean playermovement?
     
  3. TrexMatrix

    TrexMatrix

    Joined:
    Aug 8, 2023
    Posts:
    39
    I just did that then got this error Assets\Scripts\InputHandler.cs(75,51): error CS1061: 'PlayerControls.PlayerMovementActions' does not contain a definition for 'Roll' and no accessible extension method 'Roll' accepting a first argument of type 'PlayerControls.PlayerMovementActions' could be found (are you missing a using directive or an assembly reference?)
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    854
    well you defined it, and didnt share so how would we know?
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,160
    You do understand what the error means, right?

    It means a type/member you're trying to use doesn't exist in your codebase.

    In the context of the new InputSystem, it means the input action you think you have defined hasn't been defined. Either that you haven't made it, you've spelt it differently, or you've not saved your input actions asset.

    So check your spelling, check if you've made what you think should be there, and check if you've saved it.

    You can't keep making threads for these errors.
     
    bugfinders likes this.