Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by vexe · Apr 08, 2014 at 09:56 PM · importpackagenamespace

Unity overwrites files with the same name but in different namespaces on package import?

I have a couple of files that I use all over the place - Mainly utils classes.

So let's say I'm working in project1, and have a script layout of:

 Scripts
 ... Utils
 ..... Utils.cs
 ..... Helpers.cs

The classes are defined like so:

 public static class Helpers
 {
  ...
 }
 public static class Utils
 {
  ...
 }

In another different project, I also have files of the same name (they were originally the same as from the previous project, but modified more to suit the second project)

 Scripts
 ... Utils
 ..... Utils.cs
 ..... Helpers.cs

BUT: in the second project, they're defined in a separate namespace:

 namespace Project2.Utils
 {
    public static class Helpers
    {
 
    }
    public static class Utils
    {
 
    }
 }

Now I'm done working on Project2, and want to export the project as a package, and import it to project1. When I do that, Utils.cs and Helpers.cs from project2 overwrite the corresponding files in project1 even though they were in a different namespace! - This ruins things! Not cool, not cool!

Is this how this stupid thing works? should I be making my custom importer? ahh.... everything has to be custom made doesn't it? is there a tool for this, people use that I don't know about?

This doesn't happen if I manually copy the files over (don't use the import tool)

Thanks.

EDIT:

This is me in project1, importing project2 - the stuff that are not marked with "new" - should be marked!

And look at the import path - it's wrong! it should be "Complete Delegate/Utils/..." instead of "Scripts/Unapplied/..." which why things are getting ruined.

alt text

import.png (50.2 kB)
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

6 Replies

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

Answer by Tryz · May 02, 2014 at 12:47 PM

Hey Vexe,

Unfortunately, you're talking about two different things: files vs. namespaces.

Think of it from the computer's perspective, a file is a file. It doesn't care what's in the file. So when you have 'C:/YourProject/Scripts/Utils/Helpers.cs' that's just a file. If you drop another file with the same name ('Helpers.cs') into the same folder, you're asked to replace the whole file. There's no merging, splicing, or anything fancy.

Namespaces help to logically (not physically) organize classes. They are virtual buckets, that aren't restricted to a file structure (in most cases). Your OS doesn't know anything about this. It just knows about files.

Comment
Add comment · Show 1 · 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 NareshKhandla · Dec 18, 2020 at 07:17 AM 0
Share

Hello Everyone, please read our question carefully first. because you have some misunderstanding about the issue. I know this "if you drop another file with the same name ('Helpers.cs') into the same folder, you're asked to replace the whole file."

$$anonymous$$y Issue is: $$anonymous$$y packages are created with different root names with unique namespaces, scripts are located in different subfolders, but during import, all moved to the Scripts of the first one package. can you please help me how to solve this issue? Thanks, Thanks,

avatar image
3

Answer by TonyLi · Apr 09, 2014 at 05:42 PM

I believe imports go by metadata. It's likely that, due to previous imports and exports, these files have the same metadata ID in both projects. In project1, try making a copy of ColorDuo.cs and delete the original. Then export this copy and import it into project2.

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
avatar image
1

Answer by liortal · May 02, 2014 at 01:02 PM

Importing a package does not validate the contents of that file at all. It is a simple process that copies files from the source paths into your project.

As such, it cannot know that your class is a different one since it's located under a different namespace. The import process does not know that what you're importing is a class file... For all it knows, it's just a file that it needs to copy to the project's folder.

You could modify your project structure to match the namespace structure of classes (e.g: Scripts/Utils/Namespace/.../Class.cs)

This would've solved this specific issue.

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
avatar image
0

Answer by oleg_v · Oct 16, 2020 at 08:06 PM

2019, 2020 both have the same issue. Even more - packages created with different root names, scripts are located in different subfolders, but during import all moved to the Scripts of first one package. Perfect.

Comment
Add comment · Show 3 · 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 Bunny83 · Oct 16, 2020 at 09:27 PM 0
Share

That's not an issue at all. Every imported asset has a meta file next to it. This meta file uniquely identifies an asset. When you essentially duplicate an asset, use it and modify it in another project and then move it back you are the one who creates this conflict in the first place. If you want to apply breaking changes / want to create seperate a fork of an asset you should delete the meta file and let Unity generate a new one for the script asset. However I generally would not recommend to keep different versions of the same file. If you apply breaking changes to a script you may want to think about actually splitting the code and refactor the names properly. Though the meta file thing still holds true. In any case when you want to split up / duplicate and modify an existing asset you usually want to generate a new asset id.

avatar image oleg_v Bunny83 · Oct 17, 2020 at 06:53 PM 0
Share

Unity is visual editor at first, devs are not required to fill .meta manually, why we'll have to be aware of meta contents and moments when we need to fix them to fit correct import scenario? :) It's unobvious and not documented. From the other side - it's really hard to find all "wrong" meta-files.

BTW, my case is real issue, because even after cleanup/reimport/recreate all the metas i got mix of two packages at import (talking about local packages). The only solution works for me - completely change na$$anonymous$$g of all directories in two packages, i.e. $$anonymous$$y$$anonymous$$egaTool1/Scripts changed to $$anonymous$$y$$anonymous$$egaTool1/$$anonymous$$y$$anonymous$$egaTool1.Runtime. Currently it's working, but not sure will it work for assetStore downloaders or not.

ps. another related issue - export/import package with asmdefs + Editor scripts. For such combination i can't use runtime scripts to attach to objects to see my custom editors, got something like "Script is an Editor script and can't be attached to scene object". But script is not Editor script, it's located in different folder and/or related to another asmdef.

It's a pity Unity has so buggy P$$anonymous$$, i'm sure it's working, but there are too much undocumented pitfalls. Just want normal P$$anonymous$$ with XIX century dependency management :) Probably someone can post link to docs/tutorial with UP$$anonymous$$/P$$anonymous$$ tips and tricks.

avatar image NareshKhandla · Dec 18, 2020 at 07:06 AM 0
Share

right bro.. I have to get the same issue. after done the above all methods. Please help me.

avatar image
0

Answer by NareshKhandla · Dec 18, 2020 at 07:19 AM

Hello Everyone, My Issue is: My packages are created with different root names with unique namespaces, scripts are located in different subfolders, but during import, all moved to the Scripts of the first one package. can you please help me how to solve this issue? Thanks,

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
  • 1
  • 2
  • ›

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

27 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

Related Questions

How to avoid JavaScript namespace pollution? 2 Answers

How to solve "The type x exists in both y aand z"?,How to solve "The type x exists in both y and z" 1 Answer

What parts of the MSDN Library can be imported into Unity? 1 Answer

Package Import Log 1 Answer

Lightmap on different PC questions... 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