Apply matrix4x4 on GameObject transform

Hey guys,

I have a Matrix4x4 that I want to apply on my GameObject, since the matrix can have skew or non-uniform scale, I can’t use the built-in function to reach the same transformation.

So is there a way around this ?

Thanks !

(My first post on this awesome forum ! Yeeaaaaah!)

Hi! Very glad to have you on the forum (and I’m glad you think it’s awesome - I completely agree!)

The basic transform settings don’t allow you to shear/skew, since the scale values operate only along the main axes in isolation. Also, the transform’s matrix properties are read-only so that they can’t be set to something Unity can’t digest. However, you can shear an object by placing it inside a parent object, rotating it relative to the parent and then scaling the parent. For example, try taking a cube, putting it inside an empty parent, rotating the cube 45º around the X axis and then scaling the parent in the Y axis. You should see that the cube is sheared into a diamond shape.

Hey, thanks for the reply,

Ok, so yeah I would have to extract multiple rotation / scale / translation matrix from a any matrix then. But I think it’s not feasible on certain situation.

I mean, since
Rotation is :
[cosX, -sinX, 0]
[sinX, cosX, 0]
[0, 0, 1]

Translation :
[1, 0, x]
[0, 1, y]
[0, 0, 1]

Scale
[X, 0, 0]
[0, Y, 0]
[0, 0, 1]

How could I get a combination of the above basic transform with this simple matrix ?
[1, 2, 0]
[3, 1, 0]
[0, 0, 1]

(I took only 2d coordinates because I only need 2d, and it simplify the problem.)

I’m considering taking vertices of the mesh directly and transform their position, but would it be heavy on the performance ?

Thanks !

You will probably need to apply the transformation to the vertices to get the effects you want. This certainly has a higher CPU overhead than built-in transforms or animations, but you should be able to update a mesh every frame comfortably unless you have a lot of other things going on.