As the title says i am using NGUITools.Destroy(); to destroy a game object and unity standard one, either way i get the following exception...
MissingReferenceException: The object of type 'UILabel' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UIPanel.UpdateWidgets () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1519)
UIPanel.UpdateSelf () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1222)
UIPanel.LateUpdate () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1181)
This never happened before i started using my own font's, dynamic i believe. I also did some research into it and people seem to suggest you do the following in UIWidget
public virtual void MarkAsChanged ()
{
if (NGUITools.GetActive(this))
{
mChanged = true;
#if UNITY_EDITOR
if(this != null)<--ADD THIS CHECK HERE
{
NGUITools.SetDirty(this);
}
#endif
// If we're in the editor, update the panel right away so its geometry gets updated.
if (panel != null && enabled && NGUITools.GetActive(gameObject) && !mPlayMode)
{
SetDirty();
CheckLayer();
#if UNITY_EDITOR
// Mark the panel as dirty so it gets updated
if (material != null) NGUITools.SetDirty(panel.gameObject);
#endif
}
}
}
but to no avail. Does anyone have any idea how to fix this?
UPDATE:So i discovered...If you spawn a prefab with a UILabel that starts of as inactive...destroying it will cause the crash, they needed to be active at some point during the lifetime of the object before you destroy it, so it is initialisations being ignored based on an inactive state. I don't know if this only applies to UILabels or other NGUI elements.
On a slightly related note i had to change certain code in NGUI to take into account inactive elements also on the NGUITools.BringForward() as it would ignore inactive elements in and under the object you are trying to bring forward and would mess up the visual hierarchy of the object. Whether or not this was intended i do not know, but if you are experiencing a similar malady, with NGUI it seems better to have all elements active until the components Start() get's called at which point you can set it too invisible or inactive.
Good luck.