I noticed that a lot of unused namespaces are written in the scripts of my project.
So I’m thinking about whether or not to delete the codes.
Is writing unused namespaces causes a big effect to the game performance?
What’s the purpose of this question?
Let’s assume the answer is “no, they don’t affect performance.” Then what? Are you so reluctant to delete a few lines of unused code so that you can make your program more readable?
I’d wager that in the time it took you to write this post, you could have already removed them, especially considering that many IDEs can handle this automatically for you.
Why wouldn’t you delete code that isn’t being used? Performance shouldn’t be the deciding factor here. Not being lazy when riding code, so that the code is clean, and readable is.
Performance isn’t affected by these lines, just some minor differences in compile times. You should delete unused code regardless of whether it affects runtime performance or only impacts compile times. Keeping your codebase tidy and easy to understand is far more important than minor performance considerations. Readability and good coding practices should always take priority in these cases.
Exactly. The using statements are just used by the compiler to make names shorter. You don’t have to use any using statements at all. However in that case you would need to use the namespace qualified class name everywhere. So instead of
using UnityEngine;
public class MyComponent : MonoBehaviour
{
you can do
public class MyComponent : UnityEngine.MonoBehaviour
{
Having many unused namespaces imported may slightly increase compilation time but that’s not something to worry about. However having many namespaces that you actually don’t need can cause ambiguity issues. Like importing UnityEngine
and System
as both have a Random
class and the compiler can’t tell which one you meant. Such naming collisions can always happen, but the more namespaces you have imported, the higher the chance. So there’s no need to keep unnecessary ones.
Though I would keep System.Collections
as it’s in every script as default because of potential coroutine usage (it contains the IEnumerator
interface).