I have a function that will create a game object with TextMesh component dynamically, the code is as the following:
// this will create a TextMesh game object in the passed parent transform
public static FlyingText getInstanceWithTextMesh(string text, Vector3 pos, int fontSize, Color color, float speed, float duration, Transform parentTransform) {
pos.z = parentTransform.position.z;
// create game object
GameObject obj = new GameObject ("FlyingText");
obj.transform.parent = parentTransform;
obj.transform.position = pos;
obj.transform.localScale = new Vector3 (1, 1, 1);
// add TextMesh component
TextMesh t = obj.AddComponent (); // !!!!!!!!!! it will crash here !!!!!!!!!!!!!!
t.text = text;
t.alignment = TextAlignment.Center;
t.font = Resources.Load ("Fonts/"+Const.DEFAULT_FONT_NAME) as Font;
t.fontSize = fontSize;
t.color = color;
t.characterSize = 0.1f;
...
}
It will crash at this line every time 100%:
**TextMesh t = obj.AddComponent ();** Here is the crash log in Xcode: ![alt text][1] There is absolutely no problem when I tested in the PC emulator. It only happens in iOS device(Android seems not happen this). One more strange thing, If I insert a TextMesh game object by editor(not by script code) and test again. Then it won't crash any more. I absolutely don't know why.... ![alt text][2] Does anyone can help? BTW, I am using Unity 5.2.1f1 and tested in iPhone 6, iOS 8.3. [1]: /storage/temp/58480-gg.png [2]: /storage/temp/58478-no-crash.jpg
**TextMesh t = obj.AddComponent ();** Here is the crash log in Xcode: ![alt text][1] There is absolutely no problem when I tested in the PC emulator. It only happens in iOS device(Android seems not happen this). One more strange thing, If I insert a TextMesh game object by editor(not by script code) and test again. Then it won't crash any more. I absolutely don't know why.... ![alt text][2] Does anyone can help? BTW, I am using Unity 5.2.1f1 and tested in iPhone 6, iOS 8.3. [1]: /storage/temp/58480-gg.png [2]: /storage/temp/58478-no-crash.jpg