Yeah, if an active component gets destroyed then its OnDisable gets called first, so then there are two Destroy() calls for that component. It wouldn't break anything but there are cleaner ways of doing this.
No, it would just give a null reference error on the second Destroy() attempt. The Destroy() function disables the object or component first, which is what triggers the OnDisable(). On the second Destroy() call the object will already be inactive.
63
u/Successful-County640 Oct 26 '26
Since I learnt game dev I am able to understand this sub's memes better, before I didn't get much of it.
27
u/WernerderChamp Oct 26 '26
Each codebase has a few of these comment gems. Remember to add your own when the time is right.
6
u/binhosuaid Oct 27 '26
Btw, if Im not mistaken, this line of code Destroys only the component, intead of the whole gameObject. Got stumped on this a long time agoq
243
u/Banana_Twinkie Oct 26 '26
git commit -seppuku
32
u/Highborn_Hellest Oct 26 '26
the bulshido is strong with this one.
31
u/markiel55 Oct 27 '26
delete this🔫6
u/N0t_my_0ther_account Oct 27 '26
Ahh, a Unity dev
4
u/BarrelRollxx Oct 27 '26
You'll need a null check there bud
3
u/unicorngundamm Oct 27 '26
2
u/JackNotOLantern 28d ago
I remember when for some studies project i wrote in c++
delete this;1
u/thafuq Oct 27 '26
It has some 1940 germany vibes too
1
u/Last8Exile Oct 27 '26
Scary thing is you may disable some gameobject in a editor to test something and random component deep in the three will delete itself.
1
u/J-Dizzle00 29d ago
Bushido? Bushido muss gar nichts mehr
1
u/TheTybera 26d ago
// Patricide
Destroy( this.transform.parent )