Hello,
I’m having an odd issue in my build vs in editor for foreach loop. Code below. It works in the editor but when I build it out and play it, it seems like it stuck on the first iteration. See images below. I’m using Unity 2022.3.20f Windows build using IL2CPP backend. I deleted and rebuilt Library files.
I did notice that on a slower PC he does have less duplicates. I’ve also tried the function as an async task and still same issue. I’ve also made a test project with the same code but was unable to reproduce the issue.
I’m not sure what else I can look at to find and fix this issue, Any suggestions?
Thanks,
John L
Editor:
Build:
public class HotSpotTipsManager : MonoBehaviour
{
public ItemDataEditor itemDataBase;
public int itemTenmoplateCount;
public HotSpotTipTemplate[] hotspots;
[SerializeField] int databaseIdemIndex;
[Header("Spawn Tips")]
public int currentTipIndex;
public GameObject noteItemSpwanPrefab;
public Transform noteParent;
[SerializeField] bool hasItemTipsSpawned = false;
// Start is called before the first frame update
void Start()
{
databaseIdemIndex = StaticDataManager.currentSelectedModel; // Get the current selected model from the static data manager that has scriptable object data
hotspots = itemDataBase.itemTemplate[databaseIdemIndex].infoHotspots.hotSpotsTemplate; // Add the hotspots from the item template to the hotspots array
}
/// <summary>
/// Loop through the hotspots and spawn the tips
/// </summary>
public void SoawnItemTips()
{
if (!hasItemTipsSpawned)
{
foreach (var item in hotspots)
{
//Spawn the tips add to tipParent
GameObject go = Instantiate(noteItemSpwanPrefab, noteParent);
go.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = (currentTipIndex + 1).ToString();
go.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text = hotspots[currentTipIndex].hotSpotName;
go.transform.GetChild(2).GetComponent<TextMeshProUGUI>().text = hotspots[currentTipIndex].details;
currentTipIndex++; // Increment the current tip index
}
hasItemTipsSpawned = true;
}
}