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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug vsCode bug | Value not declared

Discussion in 'Scripting' started by Natsnok, Jul 28, 2022.

  1. Natsnok

    Natsnok

    Joined:
    Apr 11, 2022
    Posts:
    4
    I have often the problem that Unity didnt get a declared value and tells me its not delclared.
    Maybe someone have a clue, how i can declare the value.

    https://ibb.co/GJSFMxz

    I also have the problem with other variables that are public or private. In the first void() funktion i can use them an in the second void() funktion they arent declared.

    hier is one code example were i have the problem. Its just an example code with the problem. I know that the code isnt realy useless.

    Code (CSharp):
    1. public class P_Bullet0 : MainBullet
    2. {
    3.     P_InputScript movment;
    4.     Vector3 plMove = new Vector3(0f, 0f, 0f);
    5.     Vector3 velocity = new Vector3(0f, 0f, 0f);
    6.     public new void Start()
    7.     {
    8.         base.Start();
    9.         movment = player.GetComponent<P_InputScript>();
    10.     }
    11.     public void FixedUpdate()
    12.     {
    13.         momentumShoot();
    14.     }
    15.     void momentumShoot()
    16.     {
    17.         if (plMove == new Vector3(0f, 0f, 0f))
    18.         {
    19.             plMove = movment.GetPlayerRelativeMov();
    20.             Debug.Log("org: " + plMove + "  |  modif: " + plMove / 50);
    21.             plMove = plMove / 50;
    22.         }
    23.  
    24.         if (velocity == new Vector3(0f, 0f, 0f) && plMove == new Vector3(0f, 0f, 0f))
    25.         {
    26.             plMove = movement.GetPlayerRelativeMov();
    27.             plMove = plMove / 50;
    28.             velocity = new Vector3(0f, 1f, 0f);
    29.             velocity.y = velocity.y * BulletSpeed.y;
    30.         }
    31.     }
    32. }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,003
    You've just made a spelling mistake.
     
    PraetorBlue likes this.
  3. Natsnok

    Natsnok

    Joined:
    Apr 11, 2022
    Posts:
    4
    Shame on me...
    I just waste so mutch time in this.
    but im quide sure that it anyways happend. also if i coppy the name correctly.
    i just wait till i have the problem agan.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,945
    So unnecessary. When in doubt with such a tiny bit of code, delete the code and retype it.

    Otherwise always start from the error, you are NEVER the first person to have the error.

    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.