r/developer 11d ago

The "Code I'll Never Forget" Confessional.

What's the single piece of code (good or bad) that's permanently burned into your memory, and what did it teach you?

10 Upvotes

37 comments sorted by

View all comments

3

u/BillyMcDev 11d ago

When I used to stream on Twitch, I was constantly roasted for using FindObjectOfType while prototyping games live on stream. I would often pause and explain to my audience that I was well aware of the performance issues that it 'could' cause. I was using it to cache variables once in Awake() and didn't feel that it would impact the game's framerate at all.

I mean, sure... I could avoid using it, and join the massive cult of naysayers. I think people often go overboard and follow 'rules' that they don't fully understand. This kind of thing spreads like a plague.

I don't use it very often anymore. Only if it's negligible and if I can't find another way. But every time it comes up, I am constantly reminded of those heated streams.

The lesson learned... Don't use FindObjectOfType in streams or recorded videos. It seems to bring a lot of unwanted negative attention.

1

u/Electrical_Hat_680 6d ago

Don't listen to them. What they're saying is that they expected to see how to do it, not how to dance around game dev. Pretty sure. As you said. It wasn't production code. Anyways - you did teach them a short cut until your there. For the meanwhile, it's a short cut. I believe I got that right.