Is it better to create the Start method to find LevelManager?

Hi all!

I was looking at this lecture, and i notice that Ben “captures” the Level Manger component on OnTriggerEnter2D. Then when he tested the functionallity on the other scenes created, obviously it works, becouse when the “Lose Collider” touches the ball, it goes to find the LevelManager component first, and then change the scene. :thinking:

In my opinion, i think its better to find the level manager component on Start() method, so we can use the component anytime later, for example, if we want to change the scene when all bricks are destroyed.

I think Ben didn’t noticed that, and he did it by mistake.

What do you think guys?

1 Like

Hi @eschafir , I think in general, Start() would be the ideal method. I did it myself as well. However I think what Ben showed still fine since there’s only one case where the function being called if a ball collides with LoseCollider. In programming it’s always case by case situation. That’s my two cents. :slightly_smiling_face:

2 Likes

+1
Totally agree to this one.
In the challenge, before watching the solution, I had it put into the “Start” method. Seems to work fine too. I think this was just a mistake on Ben’s part.

I really enjoy the course though! :slight_smile:

Both ways will working.

You can call the GetComponent everytime you need him or u store a Reference to it at the Start.
It not will change the way this behaviour is working.

The Solution of putting it in the Start Method is just a performance thinking and its not a misstake from Ben. U can do it in both ways.

If you only need the Component in 1 Line of Code why u wanna store this Information from the Start? You only need the Information at the End of the Level. Think also about ur ram. U not need to store the Informaiton about ur Level Manager.

If you need the Level Manager in more Functions then you should get a reference at start. Else u not need and not will afflict the performance.