- Home /
Unity crashing when entering for loop
Answer by HellsHand · Apr 07, 2021 at 01:17 PM
Some things you may wanna look at. Check line 12, you are only setting itemTextAdd[1]
over and over for every object that goes through regardless of the index. Try changing itemTextAdd[1]
to itemTextAdd[i]
. Second ,before your for loop you set itemTextAdd
to only be game objects with the tag "Item", so the if statement within would be unnecessary, since it's just checking to see if they have the tag "item" which they all would.
Answer by borisujevic2 · Apr 07, 2021 at 01:25 PM
@HellsHand Right, the itemTextAdd[1] was a typo, and i only added that if statement in a poor attempt to prevent it from crashing.
Ah I see. Is it still crashing after changing the index? If so, is it a crash or a freeze? Scratch that I just noticed, you are adding the script to each object in itemAddText
, which will cause the Start
to run each time which causes an endless loop.
it's a freeze, sorry about the misinformation.
Best bet is to run the code from a separate script otherwise you end up with an endless recursive loop or even another method besides the Start
method.
Ahaa, i just got what i was doing, thank you very much .