So, I was using this modification until I found out it would break on build.
I've added a couple of "#if UNITY_EDITOR"'s in it to make it work for builds (as atm it will only work on the editor).
I'm actually pretty clueless about coding but this seems to work.
// (c) Copyright HutongGames, LLC 2010-2014. All rights reserved.
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
using UnityEngine;
using System.IO;
#if UNITY_EDITOR
using UnityEditor; //<- added to make the AssetDatabase available.
#endif
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Files")]
[Tooltip("Write string to a File")]
public class WriteToFile : FsmStateAction
{
[RequiredField]
[Tooltip("Set the file path, for example : Assets/myfile.txt")]
public FsmString filePath;
[RequiredField]
[UIHint(UIHint.TextArea)]
[Tooltip("The text")]
public FsmString text;
public FsmEvent successEvent;
public FsmEvent failureEvent;
public override void Reset()
{
filePath = null;
text = null;
}
public override void OnEnter()
{
if (File.Exists(filePath.Value))
{
// Create an instance of StreamWriter to write text to a file.
StreamWriter sw = new StreamWriter(filePath.Value, true);
sw.Write(text.Value);
sw.Close();
Fsm.Event(successEvent);
Finish();
}
else
{
//Stream Writer will create the file automatically
StreamWriter sw = new StreamWriter(filePath.Value, true);
sw.Write(text.Value);
sw.Close();
#if UNITY_EDITOR
//re-import file and reference in editor
AssetDatabase.ImportAsset(filePath.Value);
#endif
//Check to see if file was created successfully
if (File.Exists(filePath.Value))
{
Debug.Log("New File Made");
Fsm.Event(successEvent);
Finish();
}
else
{
Debug.Log("Error: File not created");
Fsm.Event(failureEvent);
}
}
}
}
}