Hi, I have a question about perfomance, for example I have a script called Test.cs
and inside:
public class Test : Monobehaviour {
public Start() {
}
//....
}
public class AnotherClass {
//functions and variables here...
}
Now, I attach this script (Test.cs
) to 50 gameobject, will AnotherClass
affect to the game perfomance? Or it doesn’t matter?
Is there any other risk apart from perfomance??
My final question is, it’s recommended to separate the two classes into separate files, like Test.cs
and AnotherClass.cs
?
Thanks in advance.
Bye.
Well, performance-wise it really doesn’t matter as all your scripts will be compiled to the same assembly. It’s more a question about organising. Usually it’s recommended to put one class in one file. That way you can easily find that class.
However there are cases where it’s useful to group a helper-class with the “using” class. The advantage here is that the helperclass comes with the actual class. To prevent confusion you should only include such helper classes which are exclusively used by that one class. If you have dependencies from other classes it’s better to put the helper class in a seperate file.
You might also want to group classes that belong to some kind of simple “package”. For example i wrote SimpleJSON as a single file but it contains several classes. However those classes shouldn’t actually be modified / changed, just used. Having them in one file keeps the actual project tidy.