public void SetNewInstances(HashSet <Prop> NewProps) { HashSet <PropGameObject> ToRemove = new HashSet <PropGameObject>(); foreach (Prop OldInstance in PropsInstances) { if (!NewProps.Contains(OldInstance) && OldInstance.Obj) { ToRemove.Add(OldInstance.Obj); } } foreach (Prop NewInstance in NewProps) { if (!NewInstance.Obj) // !PropsInstances.Contains(NewInstance) { NewInstance.Group = this; NewInstance.CreateObject(); } } foreach (PropGameObject PropObj in ToRemove) { Destroy(PropObj.gameObject); } PropsInstances.Clear(); PropsInstances = NewProps; }