Search Unity

Inconsistent Line Endings and Variable Errors Mac

Discussion in 'Scripting' started by unity_11b3827, Feb 11, 2019.

  1. unity_11b3827

    unity_11b3827

    Joined:
    Feb 11, 2019
    Posts:
    4
    I am getting these messages
    There are inconsistent line endings in the 'Assets/PlayerMovement.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.

    UnassignedReferenceException: The variable rb of PlayerMovement has not been assigned.
    You probably need to assign the rb variable of the PlayerMovement script in the inspector.

    rb=rigidbody and PlayerMovement is the script

    I am following along with Brackeys' video series on YouTube "How To Make A Video Game In Unity". I am on ep. 3 and have followed exactly what he is doing. My script looks exactly like his minus the comments he made in his script.

    My script:
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {

    public Rigidbody rb;

    public float forwardForce = 2000f;
    public float sidewaysForce = 500f;

    // Update is called once per frame
    void FixedUpdate ()
    {
    rb.AddForce(0, 0, forwardForce * Time.deltaTime);

    if ( Input.GetKey("d") )
    {
    rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
    }

    if ( Input.GetKey("a") )
    {
    rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
    }
    }
    }


    I have dragged the rigidbody component I have for the player to the rb variable so that rb is the rigidbody component I have for the player.

    How do I fix these errors? I am using Visual Studio on Mac.
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    You can pretty much ignore the 'inconsisten line endings' error, or allow VS to correct it for you when you open the file.

    WRT the Unassigned reference:
    - use code tags for the code you submit (so we have line numbers and correct formatting)
    - copy the entire error message including the line number, and we can then see where the assignement is wrong

    You may want to add the following to your class:

    Code (CSharp):
    1. public void Start(){
    2.   rb = GetComponent<Rigidbody>();
    3. }
    Above will load the rigidbody from your gameobject even if you forgot to connect it.
     
  3. unity_11b3827

    unity_11b3827

    Joined:
    Feb 11, 2019
    Posts:
    4
    I just opened Unity for the 1st time today and all the error messages are gone. The game runs fine and I don't get any error messages. Why did I have the problem to begin with and how come it was solved just by reopening Unity?
     
    Last edited: Feb 12, 2019
  4. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Because it's Monday.
    INB4 "but it's not Monday" -- It's always Monday.
     
  5. unity_11b3827

    unity_11b3827

    Joined:
    Feb 11, 2019
    Posts:
    4
    Now I am still getting this message again:
    There are inconsistent line endings in the 'Assets/FollowPlayer.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.

    You said I can just ignore it, but why? What is causing the problem and will it create a bunch of bugs?
     
  6. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Those luckily aren't bugs, just warnings. The reason they crop up are because when you create a new script, Unity uses a template to create a new script file. That template is a Windows-based file. Windows and Unix use different 'End of Line' marks (a purely technical Detail that almost every text processing application today handles correctly). Since you are on a Mac (a Unix-based machine), the default line endings are marked different from Windows. If you now press 'return' only once, your new script file mixes windows line endings with Unix line endings, and up comes the warning the next time the file is saved/opened. Nobody gives a damn, Unity least of all. But the warning still comes up. You can ignore it, or allow Visual Studio to fix it. There is no known bug that can be traced back to this issue. There is a (remote) possibility that a non-Standard development System (which you are NOT using) might incorrectly derive an erroneous Position in the source text whilst flagging an error. Visual Studio or Mono Develop are NOT among those that might be affected.

    But you will see this warning come up every time you create a new script, and much more often if you (like me) cross-develop on Mac and Windows.

    -ch
     
  7. Read this through: https://developercommunity.visualst...n-find-crlf-format-button-on-mac-os-veri.html
     
    ow3n likes this.
  8. AnonnyMoose

    AnonnyMoose

    Joined:
    Nov 28, 2014
    Posts:
    30
    "Visual Studio or Mono Develop are NOT among those that might be affected" - err, what? The VS debugger can't handle it at all, displaying totally wrong positions in the file when trying to step through code, so Visual Studio (Community edition on the Mac) is most certainly affected. And MS don't even have a fix for this yet after all these years.