- Home /
The question is answered, right answer was accepted
Instantiated prefab's script gives array out of range, but when already in scene works fine
Edit:: well after i did some more Checking i remmbered i did make a player, so he finds my player and take his invetory... which is empty... so that why i got the bugs... but kind of not explaining why it doesnt find the player when the window is on scene already but that another problem... any way solved
i have an inventory window i build and it has a scripts that build the slots in it generally, which worked perfectly when i had the object in scene, but when i made the window a prefab, so to not load it with the rest of the scene, but only when its first needed and after that just keep it there.
the problem is that for some reason, when i instantiate it, it gives an out of range exception, and when i did a few checking... when i sent an array of items to one of the function, for some reason the array lose its data, but it happens only when i instantiate the window...
void OnEnable()
{
GetInfo();
}
public void GetInfo()
{
solt = Resources.Load("UseableSlot") as GameObject;
panel = transform as RectTransform;
//checks if i have a player listed,which i dont
if (GameInfo.Player != null)
{
invetory = GameInfo.Player.Invetory.Values.ToArray();
Placment = GameInfo.Player.Bagspace;
slots = GameInfo.GetWindowSlots(slots, solt, invetory);
}
//cause i dont have a player it goues to here
else
{
//here i make a simple item array for checking
invetory = new ItemData[] { new ItemData(), new ItemData(), new ItemData(), new ItemData(), new ItemData() };
Placment = 5;
x = X;
y = Y;
// here i sent the array to another function, and inside this function,
// i lose the array data
slots=GameInfo.GetWindowSlots(slots, solt, invetory);
}
}
inside my GetWindowSlot() i set all the slots and return the array that holds them so i can adjust if i need to, but when i debug the inventory list in it, the array is empty for some reason.
again this happens only if use resource load() to load this window... when the window is already in scene it works fine... so i am kind of lost here .-.
tnx in advance
Follow this Question
Related Questions
How do you instantiate specific prefabs with specific spawn points in arrays? 0 Answers
Prefab files marked 'modified' everytime in git 1 Answer
Creating Scene Chunk in 2d game and Altering Prefab 0 Answers
MeshCollider instead of CapsuleCollider for TreeBrush 0 Answers
Minimum distance between cubes 1 Answer