Please make it so I can implicitly convert a bool3 into a bool (or add a helper function)

What I want is to do this

int3 position;
if (position == new int3(1, 1, 1))
{
    // Do the code
}

However, I start getting errors because for some reason this produces a bool3, rather than simply a bool. I have to write my own helper function to do this.

I personally think it makes a lot of sense to be able to implicitly convert a bool3 into a bool. However I can understand if for whatever reason you don’t agree.
If you don’t, can Unity please at least add a .or and .and properties? So at least I can go

int3 position;
if ((position == new int3(1, 1, 1)).and)
{
    // Do the code
}

Thanks! I’ve been really enjoying the new mathematics tools, but this really bugged me.

if (math.all(position == new int3(1, 1, 1))
1 Like

I find this a little cleaner

if (position.Equals(new int3(1, 1, 1))
3 Likes

math.all is the equivalent to “and” and math.any is the equivalent to “or”

In many cases, you shouldn’t be comparing vectors like that because of floating point error. Often you want something like math.distancesq(A, B) < 0.01f. Of course, there are also situations where equality is perfectly valid (eg if you’re setting the values directly from code or you have initial/sentinel values). But occasional little “bumps” like this in floating point code are good oppotunities to check your logic.

This is only true for floats, ints don’t have that issue.

1 Like