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 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#arrayinspectorarraysserialization

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.

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

Cutom Array Inspector in a Custom Inspector 1 Answer

Help Sorting large class full of variables.,Creating and array of arrays of arrays of variables with different data types. 1 Answer

Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer

Get an array of children from an existing array 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