diff --git a/src/UI/Model/UIBehaviourModel.cs b/src/UI/Model/UIBehaviourModel.cs index 21a812b..f6228f5 100644 --- a/src/UI/Model/UIBehaviourModel.cs +++ b/src/UI/Model/UIBehaviourModel.cs @@ -15,26 +15,37 @@ namespace UnityExplorer.UI.Models if (!Instances.Any()) return; - for (int i = Instances.Count - 1; i >= 0; i--) + try { - var instance = Instances[i]; - if (!instance.UIRoot) - Instances.RemoveAt(i); - else if (instance.NeedsUpdate && instance.Visible) - instance.Update(); + for (int i = Instances.Count - 1; i >= 0; i--) + { + var instance = Instances[i]; + if (instance == null || !instance.UIRoot) + { + ExplorerCore.Log($"Instance {instance?.GetType().Name ?? ""} has no UIRoot or it was destroyed!"); + Instances.RemoveAt(i); + continue; + } + if (instance.Visible) + instance.Update(); + } + } + catch (Exception ex) + { + ExplorerCore.Log(ex); } } - /// - /// Default false, if true then Update should be implemented. - /// - public virtual bool NeedsUpdate => false; - public UIBehaviourModel() { Instances.Add(this); } + public virtual void Init() + { + + } + /// /// Default empty method, override and implement if NeedsUpdateTick is true. ///