The name 'ProcessRotation' does not exist in the current context

When following along with the course, he puts in ProcessRotation(); and it does not come up as an error “The name ‘ProcessRotation’ does not exist in the current context [Assembly-CSharp]”.

When I typed in ProcessRotation(); it comes up with that error message. For some reason, it did not come up with that error message when I followed along and typed in ProcessThrust();

How do I fix this?

Error 1

Hi NinskiGaming,

Welcome to our community! :slight_smile:

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Make sure methods are not defined within the code block of another method.

Hope this helps. :slight_smile:


See also:

Understood! thank you very much for the advice, since I am new to the forum.

I have not yet compared the code to the Lecutre Project Changes, where would I find that?

Here is my code, and thank you for helping out a noob like myself :slight_smile:

public class Movement : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        ProcessThrust();
        ProcessRotation();
    }


    void ProcessThrust()
    
    {
        if (Input.GetKey(KeyCode.Space))
        {
            Debug.Log("Pressed SPACE for Thrusting");
        }
       
        void ProcessRotation()
    {
            if (Input.GetKey(KeyCode.A))
        {
            Debug.Log("Pressed A - Rotate Left");
        }
            else if (Input.GetKey(KeyCode.D))
        {
            Debug.Log("Pressed D - Rotate Right");
        }
    }
    }
}

Thank you. That’s much better. Now I am able to read your code. :slight_smile:

Where is the ProcessRotation method declared? Also check the position of the { }. If necessary, compare the curly brackets with Rick’s original code.

ProcessRotation is declared just under void Update(), and if it helps, the red squiggly line is underneath the ProcessRotation(); in the first picture that I posted, since it looks like when I pasted my code in the forum, it doesnt show the errors that I see exactly on my screen. I hope that helps!

I just clicked the yellow light bulb next to the ProcessRotation(); and I hit “Generate Method” and now it looks just like ProcessThrust(); looks, which is good! the bad part is that below where void ProcessRotation() is located, the yellow lightbulb gives me 2 options: “Remove Unused Function” and “Convert to Method”. Neither one of these methods worked for me, and I cannot use my KeyCode.A or D to control the rocket in my Debug.Log

I should have mentioned this in my last response, but when I hit the yellow lightbulb next to ProcessRotation(); and hit generate method, it created a new Private void ProcessRotation()
{ throw new NotImplementedException(); as seen below:

void Update()
    {
        ProcessThrust();
        ProcessRotation();
    }

    private void ProcessRotation()
    {
        throw new NotImplementedException();
    }

    void ProcessThrust()
    
    {
        if (Input.GetKey(KeyCode.Space))
        {
            Debug.Log("Pressed SPACE for Thrusting");
        }
       
        void ProcessRotation()
    {
            if (Input.GetKey(KeyCode.A))
        {
            Debug.Log("Pressed A - Rotate Left");
        }
            else if (Input.GetKey(KeyCode.D))
        {
            Debug.Log("Pressed D - Rotate Right");
        }
    }
    }
}

You know, I had looked over the curly brackets first, and it seemed I had them in order. Turns out I did not!

I am very sorry to bother you with these questions, but thank you very much for taking the time to look at what I thought was a complicated situation!

Good job on solving this problem yourself because it is one of the most common problems in C#. Even experienced programmers make it. If you are able to solve it yourself, you’ll save yourself a lot of time because, next time, you’ll know what to check and how to fix it. That’s why I didn’t tell you the solution directly but gave you hints only. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms