Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shepsaus000 · Apr 22, 2016 at 03:24 PM · scripting beginnermonodevelopusing

Question out of Curiosity involving namespaces

Why do we need to state the individual namespaces we want to use in our scripts? Why can't they all just be built into each script?

What I'm referring to are things like these:

 using UnityEngine;
 using System.Collections;
 etc.
 etc.


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by troien · Apr 22, 2016 at 05:16 PM

  1. You don't want to include all namespaces in your build. Because this would be a huge build. of which you wouldn't use most. Which is just a waste of disk space.

  2. Define "all". Your scripts are for instance also in a namespace (If you don't define it somewhere it will be in the default global namespace). When you use a plugin which is made by someone else, the scripts in this plugin are also in a namespace. So 'all' could theoratically be a whole lot more then you might expect :D

  3. Sometimes multiple namespaces contain classes with the same name. A good example of this is the Object class, which exists both in UnityEngine and System (but are 2 different classes). If you would include all namespaces, you would get a lot of conflicts like these.

So for example:

 using UnityEngine;
 using System;
     
 public class Example : MonoBehaviour
 {
     public Object something1; // Not allowed, which object do you mean?
 
     public UnityEngine.Object something2; // allowed
 
     public System.Object something3; // allowed
 }

And I probably forgot some reasons :p

See also : MSDN

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Apr 22, 2016 at 05:46 PM 0
Share

Indeed, when you use other class, like through inheritance, the namespace is often already used/imported. You'd find a lot of warning thrown at you a lot and you'd end up going in circles trying to delete or leave in the best placed ones. It's better to just put them in yourself as you need them.

avatar image shepsaus000 · Apr 22, 2016 at 05:52 PM 0
Share

So basically, if all of the namespaces that have ever existed were placed on the same script, we're talking about terabytes of disk space being used up O.o

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

44 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with auto moving script 1 Answer

using System, Monobehaviour, Camera, GameObject and most other thing don't work anymore/unrecognized/don't exist in current context 0 Answers

Why Visual Studio detects unused using directives? 1 Answer

Writing to Monodevelop's "Application Output" window 3 Answers

Why won't unity 3.4 monodevelp respond when I try to edit my scripts? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges