NullReferenceException from calling a method from another class.

I am new to programing and have been trying to learn how to use multiply scripts instead of just using one. I have ran into a problem with the following code. When I call the getNextTriangle method from the MasterGame script I get this error.

NullReferenceException: Object reference not set to an instance of an object
CreateTriangles.getNextTriangle (Int32 xSide) (at Assets/C#/CreateTriangles.cs:24)
MasterGame.Start () (at Assets/C#/MasterGame.cs:13)

public class CreateTriangles : MonoBehaviour {
    public GameObject trianglePreFab;
    private List<GameObject> triangles;
    private Rigidbody2D rb;

    void Start () {
        triangles = new List<GameObject>();
        for(int i = 0; i < 5; i++)
            triangles.Add(Instantiate(trianglePreFab, new Vector3(0, -10, 0),trianglePreFab.transform.rotation));

/I can call the getNextTriangle method from within this script and it works with no problems. However when I call it from my other script, its like triangles is empty, it never gets set up from Start./
public void getNextTriangle(int xSide)
for (int i = 0; i < triangles.Count;i++) //This is where the error starts.
if (!triangles*.activeInHierarchy)*
triangles*.transform.position = new Vector3(xSide, -5, 0);*
rb = triangles*.GetComponent();*
rb.AddForce(transform.up * 500);
triangles.Add(Instantiate(trianglePreFab, new Vector3(xSide, -5, 0),trianglePreFab.transform.rotation));
And here is the other script I am trying to call it from.
public class MasterGame : MonoBehaviour {
private CreateTriangles triangle;
void Start()
triangle = GameObject.Find(“This is the game object CreateTriangles is on”).GetComponent();
Any help would be greatly appreciated.

It is because your Start() method from MasterGame runs before the Start() method of CreateTriangles script. A few ways to overcome this is:

  1. You can change the script execution order to execute CreateTriangles script to run before MasterGame script from Script Execution Order Settings
  2. You can move your code from Start() method of CreateTriangles to Awake() method as Awake() is called before any Start() methods. You can read more about Execution Order of Event Functions for further details.