- Home /
having problems creating a textAsset - unity editor scripting
ok, so my idea is to simply create an empty .txt file in the assets folder. ive tried using the c# system.io but to no avail, so i figured id try using unity's built in textasset - still no luck. whenever i run the script i get a "NullReferenceException" on the line that creates the file, but idk where the problem is.
any help would be greatly appreciated :D
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public class SceneItem : Editor {
[MenuItem( "Test UI/this is a test" )]
public static void OpenMenu() {
}
[MenuItem("Test UI/submenu test/create asset")]
static void OpenSubMenu() {
var textFileToBeCreated = new TextAsset();
AssetDatabase.CreateAsset(textFileToBeCreated, "Assets/NewObject.txt");
AssetDatabase.Refresh();
}
}
that should do it
http://msdn.microsoft.com/en-us/library/ms143375(v=vs.110).aspx
There should be a circular arrow near the comment you want to convert, but I'm not sure you can alter other people's comments. I'll maark my own answer and you can mark it as accepted. Glad i helped.
Answer by CodeElemental · Oct 30, 2014 at 04:18 PM
You might try
File.WriteAllText(Application.dataPath + "/test.txt", "blabla"));
I havent tried it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170334im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Initialising List array for use in a custom Editor 1 Answer
Distribute terrain in zones 3 Answers
Script Editors for Unity 3 Answers
cannot change variables on scriptableobject asset in editor 1 Answer