Question about performance of Layer Detection

Is there a computational difference between telling to the code to get Layermask “Ground” within the if-statemen of the OnJump function compared to getting the layermask in Start() and storing the refrence in a layermask variable?

I read that Find and Get functions tend to be more processor heavy so I would assume that getting the refrence once would be less expensive?

Am I correct or incorrect?

First, I don’t know if there’s some context to your question, so this answer is more theoretical than if you’re talking about a specific circumstance.

It’s a contextual question.

The larger a scene, the more expensive Find becomes. So caching the reference would be less expensive… unless… It causes some sort of caching issue. Say you were looking for the next checkpoint, it would be something that you’d expect to change over time, so you may be better off finding it each time you need to do so…

Computers are getting so powerful these days, unless you’re looping over something every frame or it’s causing you some performance issues, it’s not often something to worry about when you’re early in your learning.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms