Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jun 20, 2016 at 01:48 PM by MadanyNO for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MadanyNO · Jun 22, 2016 at 05:09 AM · prefabe

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges