• 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 hexdump · Apr 17, 2015 at 10:24 AM · assetdatabase

Change path where asset will save

Hi,

I can create an asset using the following code:

  AssetDatabase.CreateAsset(CommonData.graph, GetPathToGraphAsset());
  AssetDatabase.SaveAssets();
  AssetDatabase.Refresh();

The user of my editor extension can change the name of the base folder this asset is stored, so, when I move the folder to the new name and try to save the asset I get an error from unity saying that it can't find the path to save it (obviously, the folder where it was stored has been moved).

Is there any way to make the asset save to the new location? I have tried AssetPath.MoveAsset without any luck.

Any help is really appreciated.

Cheers.

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

Answer by Bunny83 · Apr 17, 2015 at 11:43 AM

Well, if the asset is still loaded (and you have a reference to it) you can simply use AssetDatabase.GetAssetPath with your asset reference to get the path where it's located in the project. This should even work when the asset got moved inside Unity.

If you don't have a reference to the asset anymore your only choice is to somehow search for an instance. This can be done with AssetDatabase.FindAssets by either using the asset's name or the type of the asset (if it's a dedicated class where only one instance should exist.)

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 hexdump · Apr 20, 2015 at 10:35 AM 0
Share

Sorry Bunny83 I missread your answer and now I noticed it does not answer my question. I want to change the path the asset will save. I don't want to figure out the path it will save. I'm moving assets from a folder to another programatically and I get "asset not found" assertions when I do this.

Cheers.

avatar image hexdump · Apr 20, 2015 at 02:42 PM 0
Share

I ended using AssetDatabase.CopyAsset and then nulling the previous instance to avoid the system rewrite it when refreshing.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

How are unity references serialized? (instanceID related) 1 Answer

ObjectField Get object type(Asset, Scene Object) 2 Answers

I don't know how to use AssetDatabase.GetTextMetaDataPathFromAssetPath() 0 Answers

How to move an asset to a newly created directory in the AssetDatabase ? 3 Answers

Unity Git - Ignore Library 2 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