I have a custom script component that creates child tiled SpriteRenderer
s, then removes itself.
As implemented, it configures the new SpriteRenderer
s based on a SpriteRenderer
attached to its GameObject
, then Destroy()
s itself and the source SpriteRenderer
.
However, because I’ve put [RequireComponent(typeof(SpriteRenderer))]
on the script, I have to Destroy()
the script itself before Unity will allow me to Destroy()
the SpriteRenderer
that I no longer want.
So, my question is:
Given a script that performs the following actions, can I be sure that the current step will be finished before the script is Destroy()
ed? In other words, can I put code after Destroy(this)
and still count on it to run?
T component = this.GetComponent<T>();
// some logic
Destroy(this);
Destroy(component);