But as long as i do not enter an fix Array Index (i.e.: [0])
i alwayse get the Error:
"The Object you want to instantiate is null. "
So for me it looks like im not able to get in touch with this ID int, which is in each slotscript as Int, and is also populated. (i checked it and the Slot ID is there with the right IDnumbers).
So, how do i get hand on it, and get the right objects instanciated?
Im not able to get a reference to the script or the Object to get the SlotID int.
Since two days? What have you already tried to debug your problem? The first thing you should have done is adding a Debug.Log to print out that ID. Also since your error is that the object you want to instantiate is null we already know that the ID seems to be a valid index into your “SoftwareItem” array as we do not get an IndexOutOfBounds exception. So you may want to check if the item is actually set to an instance.
foreach(SlotScript script in GetSlotscripts)
{
int ID = script.SlotID;
Debug.Log("Going to instantiate SoftwareItem #" + ID);
var prefab = PlayerDataController.SoftwareItem[ID];
if (prefab == null)
{
Debug.LogWarning("SoftwareItem at index " + ID + " is null; skipping!");
continues;
}
SoftwareCopy = Instantiate(prefab);
// ...
Generally avoid Debug.Logs that only print a single value. If you have multiple of them you don’t know where it comes from.
With the changes above do you get the warning we print? If so you directly see which index is the problem. If you check your array you will see that the object at this index is either not set or has been destroyed.