Instantianting objects -> Unity shut down

Hi there,

I just shut down unity, cause I used more than available memory… So what happened :smiley:

private void createLabels ()
{
    float y ;
    tm = gameObject.AddComponent<TextMesh> ();
    tm.font = font;
    tm.fontSize = 100;
    tm.renderer.material = font.material; 
    tm.characterSize = 1;
    for (int i = 0; i<resolution; i++)
    { //resolution = count of values in listFloat	
	tm = Instantiate(tm) as TextMesh;
	listText.Add (tm);
    }
    float low = nejmensiZListFloat (listFloat); //return the lowest from listFloat
    for (int i = 0; i< resolution; i+=100) 
    {
	y = (listFloat [i] - low) / 100; 
	listText [i].text = listFloat [i].ToString ();
	listText [i].transform.localPosition = new Vector3 (5f * i, y * 0.5f, 0f);
	Debug.Log (tm.text);	
    }
}

I’d like to do labels for axes. But this solutions shut down Unity, cause this copied Main Camera, not the MeshText. I tried do a few copies and it worked, but i need all labels to do them adaptable due the data, which are the labeling.

Thx a lot!

This creates clone of text_mesh object with renderer, but it yells NullReferenceException: Object reference not set to an instance of an object. I dont get it. If I have the clone in Hierarchy, how it can be null reference…

GameObject g;
		g = GameObject.FindGameObjectWithTag("txt_Mesh");
		float y ;
 		//tm = gameObject.AddComponent<TextMesh> ();
		
	//	tm.text = "lala";
		//return the lowest from listFloat
		float low = nejmensiZListFloat (listFloat);
		for (int i = 0; i<2; i++) { //resolution = count of values in listFloat	
			tm = Instantiate(g) as TextMesh;
			tm.font = font;
			tm.fontSize = 10;
			tm.renderer.material = font.material;
			tm.characterSize = 0.1f;
			listText.Add (tm);			
		}

Try setting it manually through the editor, so…

public GameObject g; //Outside of the method.

Instead of.

GameObject g;
g = GameObject.FindGameObjectWithTag("txt_Mesh");

Then just drag the text mesh to your script in the editor.