I know it is possible to disable warning messages in Unity this way:
#pragma warning disable 0168 // variable declared but not used.
But there is this one warning without the id number I need to hide. Is there a way to disable it without knowing the id or can I find it somewhere?
The warning message is: BoxColliders does not support negative scale or size. The effective box size has been forced positive and is likely to give unexpected collision geometry.
And this is how it looks like in the console:

Edit: The reason I get the warning is: I have objects with multiple colliders (some mesh, some box for better performance). The colliders are nested in child objects. I am using -1 scale on the parent object to get its mirror. It is OK for mesh colliders and not for box (this warning showed after upgrading unity to newer version). It is not breaking the game but is annoying and this warning shows on the device. I simply wanted to hide the warning as it has no affect on the collision geometry in my case.
When I give a parent object negative scale, its child with the collider keeps positive scale relative to parent but still the warning shows up.
If I can't disable the warning on the device I will have to fix it but changing the collider to mesh collider is an overkill and the only way to fix it in code I can think of would be to change the child scale (with collider) to opposite of the root but I am not sure if this will work.
Edit 2: For anybody with this issue, I fixed the warning by scaling all child objects with box colliders according to world scale:
transform.localScale = new Vector3(transform.localScale.x * Mathf.Sign(transform.lossyScale.x),
transform.localScale.y * Mathf.Sign(transform.lossyScale.y),
transform.localScale.z * Mathf.Sign(transform.lossyScale.z));
Unity would force the scale to positive anyway so the end result is the same. That is why I wanted just to disable the warning.
#pragma warning disable XY
can only be used to disable compile time warnings.
What you are getting is a runtime (possibly in an editor script but still runtime) warning thrown by the according component.
You can disable(or better hide) all warnings from the console using the warnings switch in the Console Toolbar.
I'm guessing but it seems you are setting the size somewhere from e.g. a Vector3 field like
public Vector3 colliderSize;
via the inspector and then get the warming thrown while playing the app and applying that size.
If you want to limit this to at least be 0 you could do so in the OnValidate
This function is called when the script is loaded or a value is changed in the Inspector (Called in the editor only).
in order to make sure the value is corrected before the game is played or built
private void OnValidate()
{
colliderSize = new Vector3(Mathf.Max(0, colliderSize.x), Mathf.Max(0, colliderSize.y), Mathf.Max(0, colliderSize.z));
}
or invert it using e.g.
private void OnValidate()
{
colliderSize = new Vector3(Mathf.Abs(colliderSize.x), Mathf.Abs(colliderSize.y), Mathf.Abs(colliderSize.z));
}
However, in general: It is a warning - not an exception - and can be noted but ignored.
It indicates though that probably something else is wrong in your code setting that size. But it won't break your game. Unity is just kindly informing you that you tried to use a negative value somewhere before it is clamped to 0 or inverted anyway.
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