- Home /
Can I disable Debug.Logerror messages in editor mode ?
I have an editor script(ProviderManager) that is trying to destroy all the components(except some) attached to a gameobject. Few of these components have "RequireComponent" attribute on them so destroying the components that are "required" by other components results in error from Unity. However to avoid this I am running this function in recursion so that the component that cannot be destroyed now will get destroyed later in next iteration. The function works perfectly as I'd want it to work but the issue is Unity prints error messages in console when component destruction is not possible. I want a way to hide these error messages when running this function since I take care of these errors and I don't want them to appear in console.
private void RemoveAllComponents()
{
int length = GetComponents<Component>().Length;
if (length<= 3)
{
return;
}
foreach (var comp in GetComponents<Component>())
{
//Don't remove the Transform and SturfeeXRSession component
if (!(comp is Transform) && !(comp is SturfeeXRSession))
{
//Don't remove this script
if (!(comp is ProviderManager))
{
Debug.Log(" Destroying " + comp.ToString());
Debug.unityLogger.logEnabled = false;
DestroyImmediate(comp); // prints error message in console
Debug.unityLogger.logEnabled = true;
}
}
}
RemoveAllComponents();
}
Answer by N-8-D-e-v · Sep 12, 2020 at 10:57 AM
In the upper right corner of your screenshot, there are three icons. White, (should be yellow but its grayed out), and red. Click on the red icon with the '3' next to it to disable any error messages.
I meant to not have those logs appear in console at all. The code is part of a plug-in I wrote which will be used by many users. I don't want these users to get confused by looking into this error and assu$$anonymous$$g the code has bugs. I want something like try catch which in this case is catching an error thrown by Debug.LogError within Unity's code
then you would in fact use a try catch statement https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-catch
When you write something on console using Debug.Logerror it just appears on console in red. It doesn't throw any exception of any sort. If there is no exception I cannot try catch the exception and hence the issue.
Your answer
Follow this Question
Related Questions
How can i connect to the asset store? 2 Answers
Assets/Standard Assets/CrossPlatformInput/Scripts/MobileControlRig.cs(57,37): error 0 Answers
Unable to parse file ProjectSettings/ProjectVersion.txt: - And other fun errors 2 Answers
Object reference not set to an instance of an object with Assembly-CSharp 0 Answers