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 ina · Aug 30, 2011 at 07:21 AM · mobileimport.netcompile

Multiple usage of import System.Xml; in different scripts, same scene?

I am not sure how import works... When you have something in a Unity JS script that calls import System.Xml;, does it load a separate import per script, or is it now imported for all other scripts? It seems you have to put import System.Xml; on top of each script that requires it...

From that perspective, would it make more sense (efficiency wise) to aggregate all code that needs xml parsing to just one script, instead of having to call import System.Xml; each time in different scripts?

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
0
Best Answer

Answer by CHPedersen · Aug 30, 2011 at 11:10 AM

Import is the same as "using" in C#, so you can refer to this article for an explanation of what it does. :) To answer your question briefly as well, Import is limited to the file you've put it in only, so you do have to import whatever you're using in each file. Note however, that imports do not actually load a bunch of code to "make it available" for you. That's the wrong way to think about it, and import doesn't incur any kind of redundancy overhead. It simply removes the need to explicitly traverse a namespace-structure every time you refer to something.

If, for instance, you have a file that's heavy on streamreading data to and from the harddrive, then chances are you'll be declaring and referencing various types of StreamReaders and StreamWriters. Instead of having to write System.IO.StreamReader strrd = new System.IO.StreamReader every time you want a new StreamReader, you put "import System.IO" to allow yourself to skip writing that. That's all it does. It just tells the system to treat an encounter of "StreamReader" as a member of System.IO in that file, since you stated once and for all that you're going to be using that namespace.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Importing Iteration Every Time I Compile 2 Answers

Can i import already compiled code into Unity and then call functions in it? 2 Answers

IOS Development On Windows 2 Answers

Pragma or import on first line? 1 Answer

OrderedDictionary in System.Collections.Generic for mobile 0 Answers


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