Unity / VS / MAC Error

  1. I am on video 27. Manage Next States for C# Unity Developer 2D

  2. I am running Visual Studio 2017 / MAC / Latest Version of Unity

  3. My code matches the lesson and Git

However, when I try to run the code in Unity this error appears on the bottom:

There are inconsistent line endings in the ‘Assets/State.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.
UnityEditor.AssetDatabase:Refresh()
SyntaxTree.VisualStudio.Unity.Bridge.<>c:b__11_0()
SyntaxTree.VisualStudio.Unity.Bridge.<>c__DisplayClass40_0:b__0()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

I’ve looked online I think the issue is Windows conflicting with MAC somehow but I’m unclear what the solution is to continue.

Please advise.

Hi,

If you have a Mac, you need the UNIX endings.

Hi Nina - thank you - I updated the setting and restarted Unity + VS. But now I have 4 new errors in Unity:

Assets/Scripts/State.cs(13,30): warning CS0649: Field ‘State.nextStates’ is never assigned to, and will always have its default value null

Assets/Scripts/State.cs(11,48): warning CS0649: Field ‘State.storyText’ is never assigned to, and will always have its default value null

Assets/Scripts/AdventureGame.cs(9,27): warning CS0649: Field ‘AdventureGame.textComponent’ is never assigned to, and will always have its default value null

Assets/Scripts/AdventureGame.cs(10,28): warning CS0649: Field ‘AdventureGame.startingState’ is never assigned to, and will always have its default value null

I doubled check - my code matches the GIT code for the lesson. Any ideas?

These error messages mean that according to the C# compiler the variables named will never change value in a pure C# program. Of course since you are using Unity code with C# the values of these variables will change, so if you do a play test and these variables are being updated according to Unity then you don’t need to worry about these warnings.

If you want you can set the variables to initially equal null to get rid of the warning, but if you wrote the script correctly and have everything setup in Unity correctly and when you press the play button the game works like it is supposed to; then you don’t need to really worry about these warnings.

How would I do this? Right now when I push play in Unity, nothing happens. I just see the error messages. Maybe if I make it “equal null” it will let the play test continue?

First I want to say that I haven’t done the course you are taking, I just saw your post thought I could help. When you declare variables either at the top of a script like:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    public static UIManager instance;

    [SerializeField] Image blackScreen = null;

}

or inside a function/method like:

void Update()
{
     Image blackscreen = null;
}

I don’t know if that works for the Field “State.nextStates”, “AdventureGame.textComponent” or “AdventureGame.startingState”. if your C# code, as you say, matches the GIT code; did you make sure you correctly assigned everything the Unity editor?

Those are just harmless warnings, probably caused by a bug in Unity. Add = default; behind the variable declarations. For example:

string name = default;

It automatically assigns the default value. Alternatively, you could assign the default value yourself as suggested by @David_Turull. The default value is null for reference types.

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

Privacy & Terms