0

When I run this script I get NullReferenceException. When I call the script the Awake function call and works and returns the 3 variables with values stored in them, then when the WindowFunction function is called the variables empty again. I've tested the code and that's what I've found and unity is obeying the call order so it cannot be that either.

private Rect windowRect = new Rect(0, 0, Screen.width, Screen.height);
public Vector2 scrollPosition = Vector2.zero;
private int BSpace;
string[][] MeetRequests;

string[,] SortedStudentArray;
string[][] StudentArray;
string[][] userArray;
public int ItemSpacing = 10;
public int ItemWidth = 80;
public int ItemHeight = 30;

//when this script is first called
void Start()
{
    //Fetches all user Data
    string[][] userArray = GetComponent<Userdata>().CallDetail();

    string[][] StudentArray = GetComponent<Userdata>().UserSorting(userArray);

    //Calls the SortStudentArray method
    string[,] SortedStudentArray = SortStudentList();
}


public void OnGUI()
{
    //create a window
    GUI.Window(0, windowRect, WindowFunction, "Meeting Request Viewer");
}
public void WindowFunction(int windowID)
{
            //Creates a box with a scrolling bar to taverse the y axis
    scrollPosition = GUI.BeginScrollView(new Rect(Screen.width / 6, Screen.height / 6, 350, 250), scrollPosition, new Rect(0, 0, 300, 30 * SortedStudentArray.Length));

    for (int studentRow = 0; studentRow < SortedStudentArray.Length; studentRow++)
    {
        int NextItem = (ItemSpacing + ItemHeight) * studentRow;
        GUI.Label(new Rect(ItemSpacing, NextItem, ItemWidth, ItemHeight), SortedStudentArray[studentRow, 6]);
    }


    GUI.EndScrollView();
}
Oscar Dawe
  • 51
  • 9
  • Yes, I've read the post before but I believe that my problem is to do with the parsing of variable as opposed to anything else – Oscar Dawe Apr 21 '18 at 18:11
  • 1
    In that case you should reduce your code to a [mcve] there's way too much "noise" here – UnholySheep Apr 21 '18 at 18:12
  • That should be better – Oscar Dawe Apr 21 '18 at 18:15
  • 1
    So, your `Start` method creates a bunch of local variables that are then discarded - I don't see you assigning to the member variables anywhere – UnholySheep Apr 21 '18 at 18:17
  • How do I go about assigning them then? – Oscar Dawe Apr 21 '18 at 18:18
  • @Oscar don't specify a type in front of the variable name in your Start() method. – Llama Apr 21 '18 at 18:19
  • You've moved your arrays. See how it should look in my answer [here](https://stackoverflow.com/a/49543835/9481503) – Lece Apr 21 '18 at 18:19
  • Had to close this. Inside the start function, remove `string[][]` from `userArray` and `StudentArray` then `string[,]` from `SortedStudentArray`. If you don't you are declaring the variables again instead of initializing the global ones. – Programmer Apr 22 '18 at 00:18

0 Answers0