Quantcast
Viewing all articles
Browse latest Browse all 2891

Error: IndexOutOfRange: call for index 0 in an array with length 1(+)

Hi guys, I'm getting a super confusing exception while I'm working with arrays. The size of the arrays is set in the inspector / Component of a Prefab and then used in the script. The prefab will be initialized mutiple times. Maybe that's where the error is coming from, but I'm super confused right now, because it does what it is supposed to do AND throwing an error.... if (SaveManager.Instance.missionFinished) { MainMenu.Instance.MSGPanelUI(cargoInAllowed[0], cargoInput[0]); cargoInput[0] = 0; SaveManager.Instance.missionFinished = false; } More specific information: -> cargoInAllowed[] has a size of 1 and at position 0 is a 0, -> cargoInput[] has the same size as cargoInAllowed[] and at position 0 the script is writing a number. So it basically works as some kind of temporary memory. However. The error occurres in line 3 (MainMenu.Instance.....) //MSGPanel GameUI public void MSGPanelUI(int cargoIndex, int amount) { MSGGameUI.SetActive(true); RectTransform CG = Instantiate(SaveManager.Instance.Cargo_Prefabs[cargoIndex]); CG.SetParent(MSGGameUI.transform.GetChild(0)); CG.transform.GetChild(1).GetComponent().text = amount.ToString(); } this is the function I'm calling. Cargo_Prefabs[] has the length of 1 too and a RectTransfrom assigned to it. I don't think I'm doing something special here so if someone knows why this error occurres feel free to say it ;) Have fun and thanks

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>