- Home /
Android app crash in instantiating prefab
Hi, I'm facing a probleme in my application when I deploy it on android.
The application work fine but when i try to instantiate many buttons from the same prefab the application crash.
It work well in the editor but not on mobile
It may be some optimization problemes but I can't figure out what to change.
List<Hiragana> listHiragana = LessonManager.Instance.GetHiragana(); // 104 elements
foreach (Hiragana hiragana in listHiragana)
{
//création des boutons
/*
GameObject btnTemp = PrefabButtonGrid;
PrefabButtonGrid.GetComponentInChildren<Text>().text = hiragana.hiragana;
GameObject Btn_Hiragana = Instantiate(PrefabButtonGrid, GridButton.transform);
Btn_Hiragana.GetComponent<Button>().onClick.AddListener(() => ChangePanel(Pnl_Kana_In, Pnl_GridButton, hiragana));
*/
PrefabButtonGrid.GetComponent<BtnKanaScript>().kana = hiragana.hiragana;
Instantiate(PrefabButtonGrid, GridButton.transform);
}
I tried 2 approaches
1 - by editing the prefab in each loop
2 - by adding a script to the prefab and moving the listener inside the start() methode of this script.
But both methods fails.
It's seems that a smaller amount of prefab could work for the first approache but that's not what i'm looking for.
Or for the second it may be the edition of the prefab before it's instantiating that cause a probleme because when I comment the line where i assign ".kana" I manage to display all of them whithout crashing.
If someone as any clues of what is wrong I will be glad to hear it.
Thank you.
EDIT : It seems that the probleme come from the font, i try to create button from prefab with japanese text inside, and when i change the text to be latin it doesn't crash anymore. but I still don't now how to make it work, I tried a ligther font familly whithout latin alphabet but nothing changed.
Have you tried checking the Android logs on your device to see what is causing the crash, to confirm it is running out of memory?
Your answer
![](https://koobas.hobune.stream/wayback/20220613030931im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Android game does not work with prefab and works without it 0 Answers
Infinity runner - best way to spawn board in runtime. 0 Answers
instantiate random prefabs based on player camera distance 1 Answer
Unity Crashes When Spawning Prefab 2 Answers
Problem while instantiating a gameObject through C# script at runtime 2 Answers