Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
18
Question by darbotron · Aug 10, 2010 at 08:35 PM · transformmatrix4x4

Why on earth can I not just get and set the Matrix4x4 of a Transform?!?

Hi

I have a C++ game development background, and am almost entirely flummoxed by the Transform class that is used to maintain the heirarchical scene graph in Unity.

Why on earth can I not just get and set the Matrix4x4 of a Transform?

The inclusion of rotation / position / scale in the class interfaces is understandable, as there's quite a lot to take in in order to get one's head around matrices.

I'm having to go around the houses for what should be the simplest of tasks.

For example: orphaning a Transform from its parent Transform and then re-positioning it with the same world space transform it had when it was attached.

This would be a single matrix multiply and matrix assignment in most of the game engines I've worked with.

My best guess as to how to do it using Transform is to copy position & rotation and then re-set them on the object after it's been orphaned - but there's no way to ensure scaling gets carried over correctly.

Am I missing something obvious about the way Transform works? e.g. am I supposed to be doing the matrix multiply and setting the At / Up / Right by hand?

cheers,

darbotron

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
25
Best Answer

Answer by Daniel-Brauer · Aug 10, 2010 at 08:51 PM

Unity uses Transforms for rendering and for physics interactions. To this end, it does not store transformation matrices explicitly. Translation, rotation and scale are actually stored as vectors and quaternions, and transformation matrices are generated as needed.

Allowing the user to set arbitrary transformation matrices would make it difficult for the API to infer translation, rotation and scale in a lot of cases. Without valid TRS values, the physics engine would be very unhappy. In Unity 2.6, mesh scaling is done on the CPU, which also requires a separable scale (this behaviour is changing in Unity 3).

In the specific case you mention (keeping a Transform's world-space position the same while changing its parent), Unity actually does this automatically when you change Transform.parent. If you want to work around this behaviour, you have to record the Transform's local TRS, change the parent, and then re-assign the TRS values.

I know it might seem as if Unity is holding your hand too much, but this system is a lot safer and usually lets you do what you want in less code than if you were dealing with matrices the whole time.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Magnus Wolffelt · Aug 10, 2010 at 09:12 PM 3
Share

I agree with this. Even doing fairly advanced vector math (RB controllers etc), I rarely find a need to use matrices directly. It's mostly about letting go of preconceived ideas of how a 3D engine should expose its API. Start thinking about what you want to achieve, and stop thinking about matrices.

avatar image darbotron · Aug 10, 2010 at 10:12 PM 4
Share

Gotcha.

"Unity internally uses Position, Rotation, and Scale rather than $$anonymous$$atrices" is exactly the sort of answer I wanted :)

Cheers dude :)

avatar image jashan · Aug 11, 2010 at 08:06 AM 3
Share

Ah, this is really the kind of conversation I'd love to see more frequently on Unity Answers. Brings things into balance with all the "plz write $$anonymous$$$$anonymous$$O for me"-type of questions ;-)

avatar image Ricardo · Aug 11, 2010 at 08:51 AM 0
Share

@Jashan $$anonymous$$ost definitely. Would upvote twice.

avatar image Rod-Green · Oct 23, 2010 at 12:41 AM 0
Share

This would be all fine and good if unity used this kind of 'complex' transform type for all transform types. However there are a few instances when unity will return a 'simple' transform (typical 4x4 matrix) that isn't helpful to the default transform type. I.e. if you get the bind pose of a bone and try to set said bones transforms back to the bind pose you'll have to go and create the n number of matrix transformation code to extract out the position, rotation and scale from the bone bind pose 'simple' transform to then apply them back to the 'complex' transform.

Show more comments
avatar image
0

Answer by Lesliehdez · Feb 16, 2018 at 06:48 PM

I need to apply this matrix: "transformation":[15,0,0,0,0,15,0,0,0,0,15,0,0,0,0,1]

and apply it to a gameobject (.obj 3D MODEL )to obtain a new transformation. How can i do that? Thank you.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Matrix to transform bone orientation to world orientation 0 Answers

How is localScale adjusted when re-parenting transforms? 2 Answers

How to use Matrix4x4? 2 Answers

"Baking" Object scale into mesh 1 Answer

Math behind Transform.TransformPoint? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges