How to write debug log to txt file?

Hi,

I am using a visual scripting language (playmaker) to continuously track distance between two objects and save those values in a float variable. Now I want to debug that float variable and output the debug log to a txt file. Could someone help me in doing so?
(please keep in mind I am a n00b and have no prior coding experience smile )

If possible can someone tell me where I need to insert what code exactly for this to work?

namespace HutongGames.PlayMaker.Actions
{
	[ActionCategory(ActionCategory.Debug)]
	[Tooltip("Logs the value of a Float Variable in the PlayMaker Log Window.")]
	public class DebugFloat : BaseLogAction
	{
        [Tooltip("Info, Warning, or Error.")]
        public LogLevel logLevel;
		
        [UIHint(UIHint.Variable)]
        [Tooltip("The Float variable to debug.")]
		public FsmFloat floatVariable;

		public override void Reset()
		{
			logLevel = LogLevel.Info;
			floatVariable = null;
            base.Reset();
		}

		public override void OnEnter()
		{
			string text = "None";
			
			if (!floatVariable.IsNone)
			{
				text = floatVariable.Name + ": " + floatVariable.Value;
			}

			ActionHelpers.DebugLog(Fsm, logLevel, text, sendToUnityLog);

			Finish();
		}
	}
}

There are log callbacks that can be used.

https://docs.unity3d.com/ScriptReference/Application.LogCallback.html

And combine it with writing to a text file

System.IO.File

Here’s an example, it uses RegisterLogCallback which doesn’t exist anymore I think. But you can still learn from example.

http://answers.unity3d.com/questions/416675/get-debuglog-output-in-the-working-ios-build.html

More links

https://docs.unity3d.com/Manual/LogFiles.html

http://answers.unity3d.com/search.html?f=&type=question&redirect=search%2Fsearch&sort=relevance&q=log+file

I made this on this question:

I hope you’ll find what you search :slight_smile:

To create a file and put your logs into it is quite simple.

Please see my tutorial on youtube : tutorial

You only need to create a script and a function to do it.