- Home /
Is it good to have many scripts?
Hey! I am making a game and I have 11 scripts and I'm not done yet! So I was wondering is it good to have many scripts in a game... I mean will it make it slower or something? Will it affect its efficiency? If yes, how many scripts is a good number so the game won't be slower?
Typically the number of scripts will have no impact on performance. Good OOP practice says many small scripts is bigger than a single large script.
Performance comes primarily from the algorithms you choose.
Good to hear that many small scripts are better, because most of my scripts are no more than 30-40 lines!
It's absolutely ok if you have small separate scripts, as long as they are doing different roles. Once I had one script for everything and eventually it became a 1500 lines monster. It was a real pain. By the way, you can create classes for different tasks and hold their instances in one controller script. That works ok too.
@cgeopapa Each script should be just long enough to do a single job, and no longer. I have some that come in at 10 lines, including white space (A $$anonymous$$onoBehaviour with a single function call in Awake). Others, doing more complicated tasks come in at several hundred lines. $$anonymous$$uch more then that and I start to get nervous and refractor out.
There are probably legitimate uses for longer scripts. I just haven't found any yet.
Answer by unimechanic · Nov 07, 2014 at 04:14 PM
There shouldn't be difference in performance, just make sure to remove all empty event callbacks (OnGUI, LateUpdate, Update, etc) from scripts.
Your answer
Follow this Question
Related Questions
each enemy have different damage amount, how to calculate the hp remain??? 1 Answer
3D Gravity towards one object 3 Answers
Horror Game AI script recommendation? 1 Answer
expecting (, found 'OnConnectedToServer'. 0 Answers
A node in a childnode? 1 Answer