• 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
0
Question by Passero82 · Oct 29, 2017 at 12:02 AM · 2dtilemap

tileData.transform.SetTRS has no effect on scriptable tile.

I am following this example to create a scriptable tile: https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles-Example.html

Everything seems to work fine except the rotation of the tile. In the GetTileDate method I have this:

     Debug.Log("Index; " + mask + " for " + location);
                 tileData.sprite = m_Sprites[index];
                 tileData.color = Color.white;
                 Quaternion q = GetRotation((byte)mask);
                 Debug.Log(q.eulerAngles);
                 tileData.transform.SetTRS(Vector3.zero, q, Vector3.one);
 Debug.Log(tileData.transform.rotation.eulerAngles);
                 //tileData.flags = TileFlags.LockTransform;
                 tileData.colliderType = ColliderType.None;

The console output shows that I do ge a rotation from the GetRotation. It is usually (0,0,90f) however setting this using the SetTRS doesn't have any affect... The tileData.transform.rotation always seem to be (0,0,0).

What am I doing wrong here?

edit: I've done some testing and it looks like it's not just the rotation but everything...

 tileData.transform.SetTRS(Vector3.one, GetRotation((byte)mask), Vector3.one*2);

I've set this as a test and nothing got applied...

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
0
Best Answer

Answer by Passero82 · Oct 29, 2017 at 08:59 AM

I did some more testing and it appears that the

  tileData.flags = TileFlags.LockTransform;

Is the crucial part. In my code above I commented out. I did this while testing some things out. After I uncommented it, everything was working just fine. The documentation is a bit scares when it comes to this property so it wasn't actually clear to me...

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
avatar image
0

Answer by Bunny83 · Oct 29, 2017 at 01:53 AM

TileData.transform is a property and Matrix4x4 is a value type. That means your code will execute the "getter" of the property which will return a copy of the matrix. You then modify that copy. However this will have no effect on the actual internal matrix.

To change properties of value types you have to invoke the setter of the property. So you have to assign a Matrix4x4 value to the property.

 tileData.transform = Matrix4x4.TRS(Vector3.one, GetRotation((byte)mask), Vector3.one*2);

Note that this is true for any kind or property of a value type. The same holds true for the normal Transform.position for example. You can't do

 transform.position.x = 3;

You have to do

 Vector3 pos = transform.position; // call getter to get a copy
 pos.x = 3;
 transform.position = pos; // call the setter to actually update the position.



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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

135 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to stack(Sort?) objects (Trees in this case) in unity 2D TileMap 1 Answer

Reusing tilemap segments 0 Answers

[Tilemap] Can you spawn a Prefab (with colliter) together with a tile when placing it? 0 Answers

Merging Objects (many tiles into one) - 2D 2 Answers

Trouble with tilemaps as prefabs for 2D plattformer 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