I’m trying to “flip” objects with a negative X scale. In 5.3.4 this works well. In 5.4 , box colliders seem to be actually working correctly, but somewhat ironically we get spammed with this warning for every instance of a flipped collider:
BoxColliders does not support negative scale or size. The effective box size has been forced positive and is likely to give unexpected collision geometry. If you absolutely need to use negative scaling you can use the convex MeshCollider.
Now I can imagine that certain configurations with negative scales do act badly with box colliders, but in our case of a simple (-k, k, k) type of scale they seem to work well enough for our purposes. Are there lurking issues even with this type of setup? Is there a way for us to disable this warning?
Flipping objects by applying a -1 scale to one axis is something that a lot of people want to do for certain types of games, so it would be handy if this was supported as cleanly as possible.
A way to fix this is to actually set the scale of the object with the box collider that is causing the warning to be negative. The negative of this object combined with the parent object that is negative cancels them out to be positive.
I had the same Issue and it isn’t that difficult to fix too.
Somewhere in your project where you are re-scaling or resizing a GameObject (With a box collider attached to it) and or a Box collider, and the variables that calculates that getting subtracted.
Subtracting a positive from negative you now have the chance to make the size or scale negative; which mathematically wrong, like having the distance to be negative.
for example, if you are doing something like this with a variable named foo:
foo.transform.localScale = new Vector3(foo.transform.localScale.x, foo.transform.localScale.y, foo.transform.localScale.z-1f);
this will generate the error because of the chance of the z-axis scale to be 0.5f, this causes the scale to be -0.5 which is now allowed or possible. It will cause weird collisions and detection from unity side if you are going with this.
To fix this problem and avoid having the warning or negative values you must use:-
float newZScale = Mathf.Abs(foo.transform.localScale.z - 1f);
foo.transform.localScale = new Vector3(foo.transform.localScale.x, foo.transform.localScale.y, newZScale);
Mathf.Abs, take the whatever the value is and make it positive This way even if the values generated a negative value it will still get accepted and transformed into positive ones, and it will get rid of this warning in Unity 5.4.2f2.
I recently migrate to unity 5.4 I have the same issue. To me, migrate to newer version is not a good think. I always have issues. I flip the character with negative scale. What other way I could do this if are 3d or 2d. I wil try to rotate, ou flip 2d sprite. Thanks!
cek the scale of that gameobject. some scale is negative, just remove that sign.
The way to work around the error is to hae all positive but change the centre… It dont seem like you want an answer but just a place to complain, but this is a way to work around it