# How exactly does Matrix4x4.isIdentity work?

How exactly does Unity determine if a Matrix4x4.isIdentity is true?
Whether (the determinant) minus 1 is smaller than epsilon?
Whether any part of the matrix is less different from the identity’s part by epsilon?
Some other calculation?
What’s the epsilon?
Am I allowed to provide my epsilon?

It most likely just checks if it’s:
1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1

1 Like

Not exactly… they check approximately equal, not exactly equal. I know this because i tested. My questions are still not answered.

Well, unfortunately the source code for that is in native code. So only Unity themselves can answer this question. Or anyone who has access to the native source code, but I’m pretty sure they’re NDA’d so they couldn’t answer even if they wanted to.

It doesn’t look like you can add your own epsilon, though. You’ll probably just have to roll your own function and use that instead.

1 Like

Well… I decompiled Matrix4x4, and unfortunately the call is internal to the C++ side of unity. So barring someone with source code license (which bars them from sharing said source code), we don’t know their implementation of it. Well… I mean you could look at the compiled machine code to determine it… but I ain’t going to go digging down that well right about now.

As for supplying an epsilon. No, there isn’t a way to do that. The interface of Matrix4x4 offers up no way of doing so, so it’s to be assumed there is no supported way to do that. (again, of course, there are unsupported ways of actually doing this, but they are far from trivial).

Knowing the way unity usually does things. They tend to perform their checks as doubles, and they usually make their epsilon 9.99999943962493E-11 in their C# code, but I don’t know what they use in their C++ code.