• 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 elforama · May 02, 2014 at 04:35 PM · scaling

Gameobject's Z position stuck at 0 when flipping parent's x scale

Hello everyone.

I have a sprite that changes it's orientation by flipping the sign on its x axis. When this happens it's child objects (whose z axis are not set to 0) are suddenly set to 0. This change in position shows up visually, but not in the inspector. It still shows its old value there.

I've tried connecting a script to move it back to it's original position whenever this occurs, but it has no effect. Its z axis stays at 0. It stays like this even when the x axis's scale is changed back to normal.

I've been scratching my head over this for quite a while. Any help would be appreciated.

Here is an image of an empty gameobject parented to the gameobject whose x scale is about to be flipped.

alt text

In this image the xscale of the parent is now flipped. Notice the inspector still shows the child gameobjects Z value as unchanged. (You can't see the red square anymore due to the light now having the same Z position value as what it's trying to light, in this case, its parent.)

alt text

-Thank you

screenshot 2014-05-02 12.26.42.png (97.9 kB)
screenshot 2014-05-02 12.27.04.png (112.7 kB)
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
6
Best Answer

Answer by ThePunisher · May 02, 2014 at 05:28 PM

Check your parent hierarchy and make sure none of the parents have any odd scales (like z scale values set to 0).

Comment
Add comment · Show 2 · 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 elforama · May 02, 2014 at 06:39 PM 0
Share

Thank you, this was it.

I had this code:

 Vector2 newScale = transform.localScale;
 newScale.x *= -1;
 transform.localScale = newScale;

The problem was my newScale variable was a Vector2 ins$$anonymous$$d of a Vector3. This was setting the parents z scale to 0, making any children along it's z axis go to its center.

avatar image ThePunisher · May 02, 2014 at 08:19 PM 0
Share

No problem. Glad to help.

avatar image
1

Answer by sumeetkhobare · May 02, 2014 at 06:04 PM

the red square is a plane right? the planes have only one side visible texture depending on the material. And also, in the inspector,the child objects always show their properties in respect to their parent. especially, the transform component of them. So if you are actually changing the scale of the parent, that doesn't show any change in the child's properties, but it is visually able to observe in the Scene View. So, i would suggest you check the other side of the red square, may be its working correctly, and you didn't undersatnd what's happening actually.

PS: Pause the game after you flip the X scale and check the scene view..

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

21 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

Related Questions

changing camera view 3 Answers

Problem scaling parent without scaling child 0 Answers

GUI box scaling issue [C#] 0 Answers

Is this the correct way to scale my GUI? 1 Answer

My prefab is applying scale changes when hitting apply 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