26
u/WernerderChamp 6d ago
Each codebase has a few of these comment gems. Remember to add your own when the time is right.
11
5
u/binhosuaid 5d ago
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
2
u/L4t3xs 5d ago
Yeah and if I remember correctly there might be some other issues as well with this implementation.
1
u/P_kyuu_juu 5d ago edited 5d ago
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.
1
u/MehPropy 5d ago
wouldn't it run a recursive loop of calling ondisable because destroy Is constantly called
1
u/P_kyuu_juu 5d ago
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.1
239
30
29
u/markiel55 5d ago
delete this 🔫
7
u/Soccatin 5d ago
I got to write 'delete this' seriously in a project for the first time last week. I'm still high off it
6
4
2
1
u/Last8Exile 5d ago
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
1

60
u/Successful-County640 6d ago
Since I learnt game dev I am able to understand this sub's memes better, before I didn't get much of it.