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
2
Question by Azound · Feb 24, 2010 at 06:54 AM · editortextasset

Change contents of TextAsset

I'm writing a custom editor that I want to edit TextAsset contents. What I have right now is a reference to a TextAsset, and what I would love to do is edit textAsset.text, and then call EditorUtility.SetDirty(textAsset) to write the changes to disk. Unfortunately, testAsset.text is readonly. I can't figure out a way to convert from a TextAsset to a system file path, either. Does anyone know how to do this? Any way that I could figure out the local file path of an object selected in the Project panel would be helpful as well.

Thanks!

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

2 Replies

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

Answer by Shawn · Feb 24, 2010 at 07:04 PM

I was not 100% clear if you were talking about editing the text asset from inside the editor or not. The below information is for modifying files on a run-time build (I did see that your tags included the editor)...

As far as I know the TextAssets are compiled into the same assets files as your other content; which means once the application is deployed it would be compiled into something that looks like this "sharedassets0.assets". There would be no easy way to change the text asset directly without some clever file manipulation.

An easier option would be to maybe store your text assets in another directory local to your project and instead of visually linking them up as assets you would just use the .NET IO API to load the text dynamically and then you could easily save any text changes you needed back to that file. This solution would prevent you from visibly linking them in the editor, but if you needed to assign them in the editor the easiest way would be to just have a string field where you put the file name for the text file and then your application would use that filename when loading your file from code.

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 Shawn · Feb 24, 2010 at 07:17 PM 0
Share

If you are attempting to do this in the editor and would like to get the editor path to the raw text asset you can use the AssetDatabase.GetAssetPath() method:

http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.GetAssetPath.html

avatar image Azound · Feb 25, 2010 at 05:49 AM 0
Share

AssetDatabase.GetAssetPath() is exactly what I needed. Thanks! Yes, this is for in-editor.

avatar image
10

Answer by Andy Lee · Apr 14, 2016 at 12:17 PM

Though it has been late, but I want to share a quick solution for this question:

 File.WriteAllText(AssetDatabase.GetAssetPath(TEXT_ASSET), STRING);
 EditorUtility.SetDirty(TEXT_ASSET);

It should do the trick. Remember to add using System.IO;

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 IgorAherne · Dec 30, 2016 at 05:09 PM 0
Share

.thanks! .

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

2 People are following this question.

avatar image avatar image

Related Questions

Force Unity to refresh a text asset (Resources folder) 2 Answers

Editing Script In Code? 0 Answers

having problems creating a textAsset - unity editor scripting 1 Answer

Using custom external tools for custom assets? 0 Answers

[closed]Music works in editor but not in build? 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