This is my script and I tried to make "" in case it's not one of the cases:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Platform")
Debug.Log("Touching Platform");
else Debug.Log("");
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "OnTop Detector")
{
Debug.Log("On Top of Platform");
GameObject findGo = GameObject.Find("ThirdPersonController");
GameObject findGo1 = GameObject.Find("Elevator");
findGo.transform.parent = findGo1.transform;
}
else Debug.Log("");
}
But this "" not working. It's not deleting the text from the console while the game is running. And also when i stop the game and running it again it keep showing the last text of the Debug.Log.
I want to clear it if none of the If's happen in my script.
I saw this answer:
Answer
But i'm not sure if this is what I need and how to use it. Make a new script ?
And also what about errors. If I clear the Log in the console it will delete also erorrs if there will be some ?
In this screenshot it's in state after I touched the platform and then moved away from it but the text still exist in the console log:
Removing all console.log () from your project before production can be very difficult, Here is how to remove all console.log () from your project in less than a minute. Open your project in VS Code ( Since we are using Regex, It is easier to use it in VS Code ) Click on the search icon on VS Code sidebar. It will open the search option
console.log () statements are really handy tools for JavaScript development. We can easily track our app’s execution and peek its states. They can cause serious performance issues in applications especially when accidentally left in render logics. It is also risky to log sensitive data on the console in production such as passwords, keys, etc.
You will be able to match all console.logs with " or ' wrapping strings. Then you replace then with empty string. You have to select g flag, or GLOBAL option or Replace All button. Also consider, that console object has multiple methods, such as dir, table, group, etc...
Well, they can rewrite the console.log source code, but why? "it may be a good idea to write your own logger object/function that wraps around the console object": I've done this in past and it's a bad idea. The trace of the console output refers to the wrapper and not to the line that invokes it, making debugging more difficult.
The Debug.ClearDeveloperConsole()
function is used when you clear logs from an application that was built while Debug Build is enabled in your project. There is no official API for clearing the Editor log.
Most Editor functionality can be replicated with Reflection
just like hiding Gizmos and toggling the Stats Panel. I was going to write one but found this one.
This should clear every log on the Console tab.
using System.Reflection;
public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
var type = assembly.GetType("UnityEditorInternal.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
Now, you can call ClearLog();
in your else statements.
EDIT:
This has changed recently in about ~Unity 2017. Since it is done with reflection, I consider it to change again anytime if any class, variable or function used in this code is renamed by Unity. Below is the new way to do this:
public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
var type = assembly.GetType("UnityEditor.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With