How Should I Organize My Scripts?

This may seem like a stupid question to the average programmer, but it’s something That I’ve been struggling to figure out for a while: do the order of the variables (private and public) and functions in a script determine game performance, and, if so, how should I organize them? For example, should I put private before publics and put gameobjects before floats?

No, it has no impact on performance whatsoever, you can arrange them in whichever way you want in that regard.

It is however common practice to keep related items together, so public variables by them self, usually at the top, then followed by private variables, and then methods.

You can arrange variables however you want, it has no impact.

Out of curiosity, what gave you the idea that the order mattered? What caused this “struggle”?

Forget about code performance. Doesn’t matter.

But where it does matter is in your performance as a coder. Grouping things together in a logical fashion will make you work faster.

Thanks, I guess “struggle” was the wrong term to use here. It was just more of confusion than anything else. I just wanted to make sure that, when I made my scripts and such, they where running at their best performance.

As a general tip on 95% of your scripts readability and maintainability will be more important then code performance.

1 Like