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

PlayerInput does not contain any method listed in the documentation

Discussion in 'Scripting' started by lrsylux, Jul 8, 2021.

Thread Status:
Not open for further replies.
  1. lrsylux

    lrsylux

    Joined:
    Apr 2, 2020
    Posts:
    4
    I am pretty confused


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class TestPlayerInputDisable : MonoBehaviour
    7. {
    8.  
    9.     public PlayerInput playerinput;
    10.     void Awake() {
    11.         playerinput = new PlayerInput();
    12.         playerinput.DeactivateInput();
    13.     }
    14. }
    yields error: Assets\Scripts\TestPlayerInputDisable.cs(11,21): error CS1061: 'PlayerInput' does not contain a definition for 'DeactivateInput' and no accessible extension method 'DeactivateInput' accepting a first argument of type 'PlayerInput' could be found (are you missing a using directive or an assembly reference?)

    Same goes for any other method in listed in the documentation:

    https://docs.unity3d.com/Packages/c...ngine_InputSystem_PlayerInput_DeactivateInput

    What's going on here?
     
    Last edited: Jul 8, 2021
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    Well, two things.

    Most likely this means you have another class that is named PlayerInput, and it thinks you want that one instead. So check for that.

    Next, if this is the Unity PlayerInput class, you do not use "new" for it. PlayerInput inherits from MonoBehaviour, which can not be created by new. So either you need to use GetComponent or AddComponent or have a direct reference to it, which since you declared the variable as public, you could drag and drop in the inspector.
     
    Kurt-Dekker likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,970
    Did you perhaps make a script called
    PlayerInput.cs
    yourself?
     
  4. lrsylux

    lrsylux

    Joined:
    Apr 2, 2020
    Posts:
    4
    THANK YOU.

    I called my Input Action asset "PlayerInput" which then created the PlayerInput.cs file.
     
  5. DangerIncreased

    DangerIncreased

    Joined:
    Jun 15, 2021
    Posts:
    11
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. [RequireComponent(typeof(CharacterController), typeof(PlayerInput))]
    7.  
    8. public class Swat_Guy_Controller : MonoBehaviour
    9. {
    10.     [SerializeField]
    11.     private float playerSpeed = 2.0f;
    12.     [SerializeField]
    13.     private float jumpHeight = 1.0f;
    14.     [SerializeField]
    15.     private float gravityValue = -9.81f;
    16.  
    17.     private CharacterController controller;
    18.     private PlayerInput playerInput;
    19.     private Vector3 playerVelocity;
    20.     private bool groundedPlayer;
    21.  
    22.     private InputAction moveAction;
    23.     private InputAction jumpAction;
    24.  
    25.  
    26.     private void Start()
    27.     {
    28.         controller = GetComponent<CharacterController>();
    29.         playerInput = GetComponent<PlayerInput>();
    30.      
    31.         moveAction = playerInput.actions["Move"];
    32.         jumpAction = playerInput.actions["Jump"];
    33.     }
    34.  
    35.     void Update()
    36.     {
    37.         groundedPlayer = controller.isGrounded;
    38.         if (groundedPlayer && playerVelocity.y < 0)
    39.         {
    40.             playerVelocity.y = 0f;
    41.         }
    42.  
    43.         Vector2 input = moveAction.ReadValue<Vector2>();
    44.         Vector3 move = new Vector3(input.x, 0, input.y);
    45.         controller.Move(move * Time.deltaTime * playerSpeed);    
    46.  
    47.         // Changes the height position of the player..
    48.         if (jumpAction.triggered && groundedPlayer)
    49.         {
    50.             playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
    51.         }
    52.  
    53.         playerVelocity.y += gravityValue * Time.deltaTime;
    54.         controller.Move(playerVelocity * Time.deltaTime);
    55.     }
    56. }

    I am getting the same erorr please help me !
    PlayerInput' does not contain a definition for 'actions' and no accessible extension method 'actions' accepting a first argument of type 'PlayerInput' could be found (are you missing a using directive or an assembly reference?)
     
    Last edited: Jul 29, 2021
  6. Maldoc

    Maldoc

    Joined:
    May 17, 2020
    Posts:
    1

    I'm working on the exact same code from samyam video. I tried your code and it works just like mine. The error you mention didn't show up. Double check in your Package mananger that you have Cinemachine. and Input System Up to Date and installed.
     
  7. ajinkyax

    ajinkyax

    Joined:
    Dec 26, 2018
    Posts:
    5
    Im facing same issue.

    I did the same as samyam video, But same error actions is missing.

    upload_2021-9-14_22-22-3.png
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,970
    If it truly was the same, then the answer is in post #3 above.

    If it is NOT the same, please do not reply to old posts just because it sorta smelled the same.

    Instead, ALWAYS post your own new post. It's FREE!

    Also, don't post code screenshots, they're completely useless.

    Instead, if you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    To get started, right-click on the playerInput, go to the definition of that class, and find the method you're trying to use. Did you spell it properly? Show us that it really is present and yet the compiler still shows it missing. This is just standard coding process.

    Beyond that, when you post, how to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    If you are just monkey-hammer banging this in from somewhere on the intertubes, keep this in mind to save yourself a LOT of time:

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right.

    Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    If you get any errors, learn how to read the error code and fix it. Google is your friend here. Do NOT continue until you fix the error. The error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
  9. abhinavpv

    abhinavpv

    Joined:
    Apr 14, 2022
    Posts:
    6
    how did you do that
     
Thread Status:
Not open for further replies.