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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

How to Fix Error CS1061

Discussion in 'Scripting' started by Alilolz9876, Jan 23, 2022.

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

    Alilolz9876

    Joined:
    Dec 22, 2020
    Posts:
    1
    So I am having this problem when trying to import my script to my player character it comes up with this

    Assets\Scripts\InputManager.cs(23,15): error CS1061: 'PlayerMotor' does not contain a definition for 'ProcessMove' and no accessible extension method 'ProcessMove' accepting a first argument of type 'PlayerMotor' could be found (are you missing a using directive or an assembly reference?)

    How to fix??? this is my code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;
    public class InputManager : MonoBehaviour
    {
    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;

    private PlayerMotor motor;
    // Start is called before the first frame update
    void Awake()
    {
    playerInput = new PlayerInput();
    onFoot = playerInput.OnFoot;
    motor = GetComponent<PlayerMotor>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    //tell the PlayerMotor to move using the value from our movement action.
    motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
    }
    private void OnEnable()
    {
    onFoot.Enable();
    }

    private void OnDisable()
    {
    onFoot.Disable();
    }
    }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,828
    Well, the simple answer is exactly what it tells you. Your PlayerMotor class does not contain the ProcessMove class. There isn't anything else we can tell you.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,658
    You've made typos. Here's how to find and fix them:

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

    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)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    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.

    Remember: NOBODY here memorizes error codes. That's not a thing. 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.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    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 step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    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 your error. Google is your friend here. Do NOT continue until you fix your error. Your 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. If you want to learn, you MUST do Step 2.

    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!
     
  4. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    hi my code is saying this and i am trying to fix it
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class BouncySurface : MonoBehaviour
    4. {
    5.     public float bounceStrength;
    6.  
    7.     private void OnCollisionEnter2D(Collision2D collision)
    8.     {
    9.         Ball ball = collision.gameObject.GetComponent<Ball>();
    10.         if (ball = null)
    11.         {
    12.             Vector2 normal = collision.GetContact(0).normal;
    13.             ball.AddForce(-normal * this.bounceStrength);
    14.         }
    15.     }
    16. }
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,658
    Then fix it! Read my post above.
     
  6. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    i tried every move but none unity is going to say no to me :(
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I believe you mean if (ball != null). "If ball is not empty, then do some things with it" In C#, when you check for comparison you use ==. So in this statement if (ball = null), you are actually setting ball to null, not checking if it's null.
     
  8. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    no its this
    Code (CSharp):
    1. ball.AddForce(-normal * this.bounceStrength);
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, because you set ball to null just before, as I described. An error would be expected unless you check for not null.
     
  10. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    i think might be this ≠ or the other post
    (ball ≠ null)
     
  11. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    and it said this
    i did the != but didnt work also the ≠ wont work either
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    What DID it do? Did it change the error? Please post your updated code and the exact error message.
     
  13. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    Code (CSharp):
    1.  if (ball != null)
    2.         {
    3.             Vector2 normal = collision.GetContact(0).normal;
    4.             ball.AddForce(-normal * this.bounceStrength);
    5.         }
    well i did well... same
     
  14. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    Assets\Scrpits\BouncySurface.cs(14,18): error CS1061: 'Ball' does not contain a definition for 'AddForce' and no accessible extension method 'AddForce' accepting a first argument of type 'Ball' could be found (are you missing a using directive or an assembly reference?)
     
  15. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    pls comment on this one and maybe if its possible just send me the replace code
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you following a tutorial, can you provide the link? What type of object is Ball, is there also a Ball.cs file?
     
  17. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
  18. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    this is the ball code
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Ball : MonoBehaviour
    4. {
    5.     private Rigidbody2D _rigidbody;
    6.  
    7.     public float speed = 200.0f;
    8.    
    9.         private void Awake()
    10.     {
    11.         _rigidbody = GetComponent<Rigidbody2D>();
    12.     }
    13.  
    14.     private void Start()
    15.     {
    16.         AddStartingForce();
    17.     }
    18.  
    19.     private void AddStartingForce()
    20.     {
    21.         float x = Random.value < 0.5f ? -1.0f : 1.0f;
    22.         float y = Random.value < 0.5f ? Random.Range(-1.0f, -0.5f) : Random.Range(0.5f, 1.0f);
    23.         Vector2 direction = (new Vector2(x, y));
    24.         _rigidbody.AddForce(direction * this.speed);
    25.            
    26.     }
    27.         public void AddForce(Vector2 force)
    28.     {
    29.         _rigidbody.AddForce(force);
    30.     }
    31. }
    32.  
     
  19. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
    and this is the BouncySurface
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class BouncySurface : MonoBehaviour
    4. {
    5.     public float bounceStrength;
    6.  
    7.     private void OnCollisionEnter2D(Collision2D collision)
    8.     {
    9.         Ball ball = collision.gameObject.GetComponent<Ball>();
    10.  
    11.         if (ball != null)
    12.         {
    13.             Vector2 normal = collision.GetContact(0).normal;
    14.             ball.AddForce(-normal * this.bounceStrength);
    15.         }
    16.     }
    17. }
     
  20. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Should be like https://github.com/zigurous/unity-pong-tutorial/blob/main/Assets/Scripts/BouncySurface.cs and https://github.com/zigurous/unity-pong-tutorial/blob/main/Assets/Scripts/Ball.cs
     
    Bunny83 likes this.
  21. cooldoggaming5501

    cooldoggaming5501

    Joined:
    Aug 25, 2021
    Posts:
    21
  22. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You're welcome! Just know that the code I provided was written by the author of that tutorial and was mentioned on their YouTube page. Generally when I go through a tutorial, I try to write the code myself first as suggested and only "look at the answer" if I get really stuck.
     
  23. Wmarkin

    Wmarkin

    Joined:
    Sep 18, 2022
    Posts:
    2
    I typed Vector3 forceDirection = cam.transform.foreward; and the error is
    Transform' does not contain a definition for 'foreward' and no accessible extension method 'foreward' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
     
  24. Wmarkin

    Wmarkin

    Joined:
    Sep 18, 2022
    Posts:
    2
    Here are all of the References:
    [Header("References")]
    public Transform cam;
    public Transform attackPoint;
    public GameObject objectToThrow;

    [Header("Settings")]
    public int totalThrows;
    public float throwCooldown;

    [Header("Throwing")]
    public KeyCode throwKey = KeyCode.Mouse0;
    public float throwForce;
    public float throwUpwardForce;

    bool readyToThrow;
     
  25. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Would it be forward and not foreword? https://docs.unity3d.com/ScriptReference/Transform-forward.html
     
    mopthrow likes this.
  26. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,658
    Go to the documentation if you are unclear how to spell the word forward.

    Please, just fix your typos. That's all we ask, that you type 100% accurately.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    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 step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    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 your error. Google is your friend here. Do NOT continue until you fix your error. Your 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. If you want to learn, you MUST do Step 2.

    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!
     
  27. iwantaname

    iwantaname

    Joined:
    Nov 11, 2022
    Posts:
    2
    I have a problem with my code i am folowing a tutorial of sebastian Graves how to make darksouls 3 in unity episode 1 these are the errors:
    Severity Code Description Project File Line Suppression State
    Error CS1061 'InputAction' does not contain a definition for 'preformed' and no accessible extension method 'preformed' accepting a first argument of type 'InputAction' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\miel.seynaeve\My project (2)\Assets\MyInputHandler.cs 25 Active
    this is the second one:
    Severity Code Description Project File Line Suppression State
    Error CS1061 'PlayerControls.PlayerMovementActions' does not contain a definition for 'Camera' and no accessible extension method 'Camera' accepting a first argument of type 'PlayerControls.PlayerMovementActions' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\miel.seynaeve\My project (2)\Assets\MyInputHandler.cs 26 Active

    this is my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    namespace MS
    {
    public class MyInputHandler : MonoBehaviour
    {
    public float horizontal;
    public float vertical;
    public float moveAmount;
    public float mouseX;
    public float mouseY;
    PlayerControls inputActions;
    Vector2 movementInput;
    Vector2 cameraInput;
    public void OnEnable()
    {
    if (inputActions == null)
    {
    inputActions = new PlayerControls();
    inputActions.PlayerMovement.Movement.preformed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
    inputActions.PlayerMovement.Camera.preformed += i => cameraInput = i.ReadValue<Vector2>();
    }
    inputActions.Enable();
    }
    private void OnDisable()
    {
    inputActions.Disable();
    }
    public void TickInput(float delta)
    {
    MoveInput(delta);
    }
    private void MoveInput(float delta)
    {
    horizontal = movementInput.x;
    vertical = movementInput.y;
    moveAmount = Mathf.Clamp01(Mathf.Abs(horizontal) + Mathf.Abs(vertical));
    mouseX = cameraInput.x;
    mouseY = cameraInput.y;
    }
    }
    }
     
  28. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,828
    The best part of doing a tutorial, is that you can go back, reread the code they have and compare it to what you have.

    So, do this. Stop making typos. I'm pretty sure preformed is not what they show in the tutorial and you have a simple typo here.
     
  29. iwantaname

    iwantaname

    Joined:
    Nov 11, 2022
    Posts:
    2
    it's the exact code from him you can look
     
  30. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,658
    Nope. That's not how it works. YOU are doing the tutorial. YOU need togo back and look and fix your mistakes.

    Is it really "preformed"? That seems unlikely. I would guess it is "performed"

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    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 step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    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 your error. Google is your friend here. Do NOT continue until you fix your error. Your 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. If you want to learn, you MUST do Step 2.

    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!

    Finally, when you have errors, don't post here... just go fix your errors! Here's how:

    Remember: NOBODY here memorizes error codes. That's not a thing. 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.

    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)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    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.
     
  31. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,828
    If it was the exact code and the tutorial wasn't getting an error, it's likely you shouldn't either. With the possible exception that they skipped over something or they are a really old tutorial, it should work.

    But, that being said, before I replied to you, I actually did go and look because I was curious about the tutorial content itself. Which is why I know you are making typos.

    When you get an error like this and it tells you exactly what word the issue is with, you need to go back to the tutorial, compare them side by side. Read the two words letter by letter. Retype it if you need to. All common debugging steps that as you gain experience will become super easy for you to do.
     
    Kurt-Dekker likes this.
  32. unity_sDZ1d78y5JYSQw

    unity_sDZ1d78y5JYSQw

    Joined:
    Mar 31, 2021
    Posts:
    1

    Finally a person who as explained it in plain English..Respect and thank you
     
Thread Status:
Not open for further replies.