ArenMook, could you please elaborate what you mean by "UI hierarchy"? Does there need to be a specific NGUI component at the top of the hierarchy?
I have started to swap out the bad null parent stuff for what you guys are suggesting, and I have found myself at a point where I can cause the crash on demand again.
I create my "SectionMenuView" object this way:
GameObject prefab = ResourceManager.getResource<GameObject>("Prefabs", "Section");
GameObject go = GameObject.Instantiate(prefab) as GameObject;
Transform t = go.transform;
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
SectionMenuView sectionMenu = go.AddComponent<SectionMenuView>();
sectionMenu.section = section;
Inside the SectionMenuView I proceed to make its child elements:
// Method 1 - Works 100% of the time
GameObject prefab = ResourceManager.getResource<GameObject>("Prefabs", "Cue");
GameObject child = NGUITools.AddChild(this.gameObject, prefab);
CueView cueView = child.AddComponent<CueView>();
// Method 2 - Crashes 100% of the time
CueView cue = CueView.newInstance<CueView>(this.gameObject, "Prefabs", "Cue");
I have modified the newInstance method:
public static new T newInstance
<T
>(GameObject parent,
string path,
string name
) where T : MonoBehaviour
{
GameObject prefab = ResourceManager.getResource<GameObject>(path, name);
GameObject instance = NGUITools.AddChild(parent, prefab);
return instance.AddComponent<T>();
}
As far as I can tell the newInstance method does exactly the same thing as the working lines in the SectionMenuView.
Can you guys spot anything I'm doing wrong in the newInstance method?