Get the Right Component!

I’ve been using Unity for a while, but I’ve only been coding (for realz) for about a year. I’m currently refactoring some of the code I wrote a year ago, and seeing lots of things I can do better.

One thing I’m seeing way too much of is this:

I’m assigning a GameObject in the inspector, and then getting the Image component in Start().

What’s wrong with this?

In many cases I don’t need the GameObject beyond the Start() method, so having it hanging around is pretty much pointless, and getting all those components at the start (or any other time) causes an unnecessary delay.

Continue reading “Get the Right Component!”

Get the Right Component!