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
1
Question by ZenithCode · Oct 29, 2012 at 10:30 PM · editorasset bundles

Change file name in a scriptable object

I am building asset bundles from a scriptable object and I would like to change the filename according to the build options I set in my scriptable object.

I've tried object.name = "newName" however that is does not change the filename.

Any pointers please? Thanks

Comment
Add comment · Show 5
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 liszto · Oct 29, 2012 at 10:48 PM 0
Share

If it's an object in Unity scene, this must work :http://docs.unity3d.com/Documentation/ScriptReference/Object-name.html

But if you really want to change the filename I think it's better to use C#/Unity functions like this : http://docs.unity3d.com/Documentation/ScriptReference/Path.GetFileName.html or System.IO.Path.GetFileNameWithoutExtension( m_goYourObject );

I don't really know if it's what you search or want :/

avatar image ZenithCode · Oct 29, 2012 at 10:52 PM 0
Share

Object.name does not work on a scriptable object.

GetFileName does what it states, it gives you the file name only. I need to change that.

avatar image liszto · Oct 29, 2012 at 10:57 PM 1
Share

Yes I know but with some more lines extract from one of my C# script :

http://pastebin.com/pxh8$$anonymous$$qdm

And with some ideas from your $$anonymous$$d, you can do great things you know :) I hope this can help you

avatar image ZenithCode · Oct 29, 2012 at 11:00 PM 0
Share

Cheers. I'll try that and get back to you!

avatar image liszto · Oct 29, 2012 at 11:00 PM 0
Share

ok no problem ;)

3 Replies

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

Answer by ZenithCode · Oct 30, 2012 at 10:36 AM

@liszto Thanks you got some ideas churning which helped me solve the problem.

Final solution is this:

             string listingFilePath = Path.GetFullPath(myAssetPath);
             string listingFilePathNoFileName = listingFilePath.Remove(listingFilePath.Length - (myAssetPath.Length)); //Remove filename
             string listingRelativePath = AssetDatabase.GetAssetPath(myAsset); //Get path withing the unity folder 
             string listingFullPath = listingFilePathNoFileName + listingRelativePath;
             string newFilePath +="mychanges";
             File.Copy(listingFullPath, newFilePath, true);
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 liszto · Oct 30, 2012 at 10:56 AM 0
Share

You're welcome :)

avatar image
13

Answer by silentslack · Feb 05, 2016 at 02:41 AM

Think I found a better way to rename an asset:

 string assetPath =  AssetDatabase.GetAssetPath(myAsset.GetInstanceID());
 AssetDatabase.RenameAsset(assetPath, newName);
 AssetDatabase.SaveAssets();
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 Mddmd · May 29, 2017 at 08:47 AM 0
Share

How to change an extension too..

avatar image
0

Answer by JouPal · May 23, 2020 at 12:03 PM

 public bool renameOnValidate = false;
 public int id;
 public int itemName
 
         
 private void OnValidate()
 {
             if (renameOnValidate)
             {
                 string thisFileNewName = id + "_" + itemName;
                 string assetPath = UnityEditor.AssetDatabase.GetAssetPath(this.GetInstanceID());
                 UnityEditor.AssetDatabase.RenameAsset(assetPath, thisFileNewName);
                 renameOnValidate = false;
             }           
 }            

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

13 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

Related Questions

Prevent BuildStreamedSceneAssetBundle showing progress bar 0 Answers

Queue method to be called after asset processor is done 0 Answers

How to import the object from server to unity 2 Answers

Asset bundles for gaming consoles (ps3, xbox and wii)? 0 Answers

Some GameObjects not visible in android build but work fine in the editor? 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