- Home /
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.
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.