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 /
  • Help Room /
avatar image
0
Question by fluxhackspro · Apr 20, 2018 at 09:05 PM · arrayarrays

Array of arrays, what am i doing wrong?

Hello trying to disable all gear on an AI. Each "class" is an array of gameobjects and i make an array of those arrays to disable ALL classes. But later i need to select a specific class with an index thats why im using an array of arrays. But first i try to understand this "dubble" array. In the start function i set each class in the "allGear" array which is the array of all arrays. But i get an error. What am i doing wrong?

Thanks

     [Header("Equipment for each profession")]
     public GameObject[] noProfession;
     public GameObject[] milita;
     public GameObject[] mason;
     public GameObject[] carpender;
     public GameObject[] archer;
     public GameObject[] scribe;
     public GameObject[] hunter;
 
     public GameObject[][] allGear;
 
     [HideInInspector]
     public int professionIndex = 0;
     //rankIndex
     //1 = hunter
     //2 = mason
     //3 = carpender
     //4 = milita
     //5 = archer
     //6 = scribe
     void Start ()
     {
         allGear [0] = noProfession;
         allGear [1] = hunter;
         allGear [2] = mason;
         allGear [3] = carpender;
         allGear [4] = milita;
         allGear [5] = archer;
         allGear [6] = scribe;
     }
 
     public void UpdateGear (int index)
     {
         //Disable all gear;
         for (int j = 0; j < allGear.Length; j++) {
             for (int i = 0; i < allGear [j].Length; i++) {
                 allGear [j][i].SetActive(false);
             }
         }
     }

Comment
Add comment · Show 1
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
avatar image Positive7 · Apr 20, 2018 at 09:31 PM 1
Share

What is the error?

EDIT: Nvm.. After a second look it is a null reference, because your array is not initialized.

 public GameObject[][] allGear = new GameObject[7][];

consider using System.Linq; And just do:

 //Disable all
 foreach (var gear in allGear.Select$$anonymous$$any(x => x))
         {
             gear.SetActive(false);
         }
 
 Enable all by profession id
 foreach (var gear in allGear.First(x => x == archer))
         {
             gear.SetActive(true);
         }

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fluxhackspro · Apr 21, 2018 at 05:56 AM

Thank you @Positive7 for the correct solution! After a second look it is a null reference, because your array is not initialized.

 public GameObject[][] allGear = new GameObject[7][];
 
 
Comment
Add comment · Show 1 · Share
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
avatar image Positive7 · Apr 21, 2018 at 06:51 AM 0
Share

No problem!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom inspector array issues for loop 0 Answers

Moving spawned enemies randomly towards several pre-defined positions 1 Answer

Convert string to array name? 0 Answers

how to not repeat random array 0 Answers

How do I view an array that is inside of an array in the unity inspector? 0 Answers


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