I’ve a spell system the place a the spell is a self-contained recreation object dealing with all of the logic. When completed, it destroys itself. This works nice
Then I added a second recreation object dealing with animation, and bundled it below a mother or father object. The spell nonetheless destroys itself high quality, and the animation object destroys itself after the animation, nice. That leaves me with the mother or father which ought to destroy itself when all youngsters are completed and gone.
The difficulty is that the kid objects don’t have any details about one another, nor do they destroy themselves in any fastened order. (The participant has the choice to resolve spell-by-spell if they need sound and/ or animations to be enabled; generally there is just one little one, generally 3).
Whereas I may test within the mother or father in every Replace if there are kids, it looks as if that will add an excessive amount of overhead with a number of spells for a test that’s more often than not not helpful.
Informing the mother or father through UnityEvent like this (executed on the kid)…
public UnityEvent OnCleanupDone;
public void DestroyEverything() {
Destroy(gameObject);
OnCleanupDone?.Invoke();
}
…can also be not working, since when the mother or father subscription operate known as, the kid continues to be alive.
How can I deal with this in a strong and environment friendly means?


