Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
4
Question by mandarin · May 30, 2013 at 12:20 PM · editormovedirectoryreimport

Possible to move directory without reimporting assets?

When I drag a sub directory from a directory to another in the Project view, the directory gets moved instantly-ish. When I move the same sub directory using an editor script, Unity reimports all of the assets in the moved directory.

I have tried two different ways of moving files in my script:

 FileUtil.MoveFileOrDirectory("Assets/Resources/DirName", "Assets/Audio/DirName");

And

 try {
     Directory.Move("Assets/Resources/DirName", "Assets/Audio/DirName");
 }
 catch (Exception e) {
     Debug.Log("Move failed: "+e.Message);
 }

Is there any way of moving a folder using a script, without triggering a reimport?

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

3 Replies

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

Answer by mandarin · May 30, 2013 at 01:34 PM

The solution was to move the files using AssetDatabase.MoveAsset(). That will make sure to keep the meta files intact and it doesn't trigger a reimport.

Here's an example:

 DirectoryInfo dir = new DirectoryInfo("Assets/Dir");
 FileInfo[] files = dir.GetFiles("*.wav");
 
 foreach (FileInfo file in files) {
     string status = AssetDatabase.MoveAsset(
                         "Assets/Dir/" + file.Name,
                         "Assets/NewDir/" + file.Name);
     
     // Everything is OK if status is empty
     if (status != "") {
         Debug.Log(status);
     }
 }

Remember to include

 using System.IO;

at the top of your class.

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 KruegerT · May 14, 2019 at 03:25 PM 0
Share

It still triggers a reimport, once you tabbed out and in to the Editor. (5.6.5f1)

avatar image
-1

Answer by Dave-Carlile · May 30, 2013 at 12:25 PM

The only relevant documentation that I'm aware of says to only move folders from within the editor.

"Never move any assets or organize this folder from the Explorer (Windows) or Finder (OS X). Always use the Project View!

There is a lot of meta data stored about relationships between asset files within Unity. This data is all dependent on where Unity expects to find these assets. If you move an asset from within the Project View, these relationships are maintained. If you move them outside of Unity, these relationships are broken. You'll then have to manually re-link lots of dependencies, which is something you probably don't want to do."

Calling functions to do the moving is most likely the equivalent of using Explorer or Finder.

Comment
Add comment · Show 4 · 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 mandarin · May 30, 2013 at 12:44 PM 0
Share

Hi Dave.

Thanks. After a couple of tries, I figured there were some meta-files that got out of sync. I did however find a solution. I'll post it as an answer to my own question.

avatar image Rasterizer · Jun 06, 2013 at 06:19 PM 0
Share

What was your solution? How did you get the meta-files in sync again?

avatar image Dave-Carlile · Jun 06, 2013 at 06:24 PM 1
Share

@Rasterizer Refer to the accepted answer.

avatar image TTTTTa · Dec 02, 2017 at 10:52 PM 0
Share

Not sure why this answer was downvoted. This is a perfectly acceptable solution to move assets and ensure the assets is not re-imported. It is also useful for rena$$anonymous$$g folders or assets.

avatar image
0

Answer by KirillKuzyk · Jun 13, 2017 at 08:55 PM

I was wondering how to move folders with AssetDatabase.MoveAsset() for a long time.

Finally, I have an answer. To do this, you need to create a destination folder hierarchy. For example:

This code will only work if a folder Assets/WebGLTemplates/Resources exists.

 AssetDatabase.MoveAsset("Assets/Resources/sounds", "Assets/WebGLTemplates/Resources/sounds");
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

18 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

Related Questions

Linking a file outside the Asset folder to update an asset on reimport 0 Answers

Can Unity not replace customized values on re-imported packages? 0 Answers

Auto-refresh assets after changing scriptable object 0 Answers

Finding path(Directory) of Script from class 1 Answer

Unity double save/back-up 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