• 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Alex-Gama · Nov 10, 2015 at 04:34 PM · c#arrayinspectorserializationarrays

Array not updating in inspector

I have a public array that holds a custom type and it used to update in the inspector when I added something new to the array in the inspector. Now when I add something to the array it doesn't update in the inspector even though I can see that it is being updated via debug.log.

The script looks like this:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 
 public class Walkers : MonoBehaviour
 {
     
     public Walker[] walkers;
     public float[] blah;
 
     public static Walkers walkersRef;
     // Use this for initialization
     void Start ()
     {
         walkersRef = this;
         walkers = FindObjectsOfType<Walker>();
         blah.Initialize();
     }
     
     void Update ()
     {
     }
 
     public void AddWalker(Walker wlk)
     {
         Debug.Log("Here");
         System.Array.Resize(ref(walkers), walkers.Length+1);
         wlk.ID = walkers.Length;
         walkers[walkers.Length-1] = wlk;
         System.Array.Resize(ref (blah), blah.Length + 1);
         blah[blah.Length - 1] = wlk.timeWhenLoaded;
 
         Debug.Log(walkers.Length);
         Debug.Log(blah[blah.Length - 1]);
     }
 
     public WalkerData GetWalkerData(int index)
     {
         WalkerData walkerData = new WalkerData();
         walkerData.ID = walkers[index].ID;
         walkerData.timeWhenLoaded = walkers[index].timeWhenLoaded;
         walkerData.destroyTime = walkers[index].destroyTime;
         walkerData.saved = walkers[index].saved;
         return walkerData;
     }
 
     public void DeleteAll()
     {
         foreach(Walker walker in walkers)
         {
             Destroy(walker);
         }
     }
 }
 
 
 

Note that the blah array was quickly made just to double check that the walkers array is definitely being updated (Which it is). Also the blah array isn't being updated in the inspector either even though that's also being updated. If it would help I'd like to also mention that the walker script has a walker data class that is being serialized.

Walker class

 using UnityEngine;
 using System.Collections;
 
 public class Walker : MonoBehaviour
 {
     public long ID;
     public float timeWhenLoaded = 0.0f;
     public float destroyTime;
     public float timeWhenDestroyed = 0.0f;
 
     public bool saved = false;
 
     // Use this for initialization
     void Start ()
     {
         timeWhenDestroyed = timeWhenLoaded + destroyTime;
         WalkerData walkerData = new WalkerData();
         walkerData.ID = ID;
         walkerData.timeWhenLoaded = timeWhenLoaded;
         walkerData.destroyTime = destroyTime;
     }
     
     // Update is called once per frame
     void Update ()
     {
         if(AudioManagement.audioManagment.currentPlaybackTime >= timeWhenDestroyed || AudioManagement.audioManagment.currentPlaybackTime <= timeWhenLoaded)
         {
             this.GetComponent<SpriteRenderer>().enabled = false;
         }
         else if(AudioManagement.audioManagment.currentPlaybackTime < timeWhenDestroyed && AudioManagement.audioManagment.currentPlaybackTime > timeWhenLoaded)
         {
             this.GetComponent<SpriteRenderer>().enabled = true;
         }
     }
 }
 
 [System.Serializable]
 public class WalkerData
 {
     public long ID;
     public float timeWhenLoaded = 0.0f;
     public float destroyTime;
     public bool saved;
 }

Any help into why the arrays aren't updating in the inspector would be greatly appreciated.

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 Alex-Gama · Nov 17, 2015 at 12:59 PM 0
Share

Hey guys I'm still stuck with this, I've looked into serialization more but nothing I've tried has worked. I'm kinda convinced I'm making some really stupid mistake that I haven't noticed yet.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Inspector Doesn't Update Array Elements When Updated In Array Constructor 1 Answer

Array problems 3 Answers

Classes that contain an array of its own type do not appear in the inspector 2 Answers

Distribute terrain in zones 3 Answers

Array of Arrays of GameObjects/Prefabs (C#) 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