I’ve a spell system the place a the spell is a self-contained sport object dealing with all of the logic. When achieved, it destroys itself. This works nice
Then I added a second sport object dealing with animation, and bundled it beneath a guardian object. The spell nonetheless destroys itself superb, and the animation object destroys itself after the animation, nice. That leaves me with the guardian which ought to destroy itself when all youngsters are achieved and gone.
The difficulty is that the kid objects haven’t any details about one another, nor do they destroy themselves in any fastened order. (The participant has the choice to determine 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 guardian in every Replace if there are kids, it looks like that might add an excessive amount of overhead with numerous spells for a test that’s more often than not not helpful.
Informing the guardian 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 guardian subscription operate is named, the kid remains to be alive.
How can I deal with this in a strong and environment friendly approach?
