Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by DiGiaCom-Tech · Mar 18, 2015 at 12:38 AM · editor-scriptingclassesarray of gameobjects

Updating Public Class Array Not Updating Inspector

I have created a public class array containing a GameObject, some integers, and some Strings...

     [System.Serializable]
     public class SpawnerObject
     {
         public GameObject Object;
         public int Weight = 1;
         public int WeightValue;
         public string Name;
         public string Tag;
         public int TotalSpawned;
     }
     public SpawnerObject[] SpawnerObjects;

I also have a method that attempts to load child objects from a specified GameObject (PrefabsFolder) into this class array (see code below). The method is called from the associated editor code button and it is stepping through the 'LoadPrefabsFolder' code but not updating the class array completely...

     public void LoadPrefabsFolder()
     {
         if (PrefabsFolder)
         {
             // Get count of children in prefab folder
             int Prefabs = PrefabsFolder.transform.childCount;
             // Update spawner objects array
             SpawnerObject[] SpawnerObjects = new SpawnerObject[Prefabs];
             // Add each prefab to the spawner objects array
             for (int i = 0; i < Prefabs; i++)
             {
                 Transform tObjects = PrefabsFolder.transform.GetChild(i);
                 GameObject oObject = tObjects.gameObject;
                 SpawnerObject Prefab = new SpawnerObject();
                 Prefab.Name = tObjects.name;
                 Prefab.Tag = tObjects.tag;
                 Prefab.Object = oObject;
                 Prefab.TotalSpawned = 0;
                 Prefab.Weight = 1;
                 Prefab.WeightValue = 1;
                 SpawnerObjects[i] = Prefab;
             }
         }
     }
 

Note that I have removed code that performs various checks (e.g. reports missing objects to the debug log) to simplify the code for you. Can someone tell me what I'm missing/doing wrong here?

ThanX - DJ

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DiGiaCom-Tech · Mar 21, 2015 at 05:04 PM

OK ... I found the problem! In the 'LoadPrefabsFolder' method I was updating the inspector object itself. The fix was to create & load a temporary class object and then set the inspector class object equal to it (the first & last lines of code changed)...

             // Update spawner objects array
             SpawnerObject[] tSpawnerObjects = new SpawnerObject[Prefabs];
             // Add each prefab to the spawner objects array
             for (int i = 0; i < Prefabs; i++)
             {
                 Transform tObjects = PrefabsFolder.transform.GetChild(i);
                 GameObject oObject = tObjects.gameObject;
                 SpawnerObject tPrefab = new SpawnerObject();
                 // Set name & tag
                 tPrefab.Name = tObjects.name;
                 tPrefab.Tag = tObjects.tag;
                 // Set object
                 tPrefab.Object = oObject;
                 // Set defaults
                 tPrefab.TotalSpawned = 0;
                 tPrefab.Weight = 1;
                 tPrefab.WeightValue = 1;
                 // Set the prefab as a spawner object
                 tSpawnerObjects[i] = tPrefab;
             }
             // Update the inspector
             SpawnerObjects = tSpawnerObjects;
 
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 marx13maxz · Jun 19, 2018 at 02:50 PM 0
Share

How did you add an entry to your array? I am getting this Error NullReferenceException: Object reference not set to an instance of an object this is the line it is pointing. ButtonPairs[0].SelectButton = button.name;

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

21 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

Related Questions

Editor Script for selecting class property for saving 1 Answer

Get list of all "Action" classes 1 Answer

(Custom WIndow) Access class color from another script and override it 0 Answers

Show a dropdown for C# classes in inspector. 2 Answers

Make custom editor for generic class to apply to all current and future child classes 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