I created a notification panel in my scene, that shows notifications when something happens. Those notifications are just buttons that get added as children to the ScrollingObjectCollection
:
The issue that I have, is that after deleting one notification (that one in the middle) the collection gets not updated. But clicking in the inspector on the UpdateCollection
-Btn will update the collection. I debugged and saw that it is aware that after deleting one, only two notifications are left.
private void DeleteNotification()
{
if (NotifyManager.Instance.RemoveNotificationFromList(Id))
{
Destroy(this.gameObject);
NotifyManager.Instance.ScrollingCollection.UpdateCollection();
}
}
This is what the button UpdateCollection
from the ScrollingObjectCollection
in the Inspector calls and its the same method that I'm calling too:
if (GUILayout.Button("Update Collection"))
{
scrollContainer.UpdateCollection();
EditorUtility.SetDirty(scrollContainer);
}
Does somebody know how to update that collection on runtime via code?
My setup:
Ok, I fixed it by myself. The problem was that all happend in one frame and the ScrollingObjectCollection
was not in a state where the notification was deleted. So I created another method in my NotifyManager where I wait for the end of the frame and then call UpdateCollection
.
private IEnumerator WaitBeforeUpdateCollection()
{
yield return new WaitForEndOfFrame();
scrollingCollection.UpdateCollection();
}