• 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
Question by Jacho_Mendt · Feb 01, 2019 at 12:10 PM · transformpositionbugparent

parent Transform.position unexpected behaviour when changing position

Hello,

I'm having some trouble with an unexpected behaviour of changing the position of a gameobject.

I have a gameobject, called worldobject, which holds two components, WorldManager and WorldDrawManager. After the calculations of the world data is completed (i'm creating an icosphere), WorldManager calls WorldDrawManager to draw all world chunks (each face of the original icosahedron is a chunk) as new gameobjects whose parent is worldobject and position is Vector3.zero.

Now, everything works fine when the gameobject is at position (0,0,0), but when I change the position of said object (for example at 0,-100,0) the icosahedron gets STILL drawn around the (0,0,0) origin point. The chunk objects' positions are each shown as (0,100,0), even if I explicitly set them to Vector3.zero.

Inspecting worldobject before I start the game shows its gizmo at the correct position, but after I complete the world generation its gizmo is shown at (0,0,0) even if its position in the component is correctly set.

Is this a bug or am I doing something wrong?

Thanks in advance!

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by bpaynom · Feb 01, 2019 at 12:30 PM

Your are instantiating them using world position instead of your object relative position. You can

  • use transform.localPosition to set the position

  • calculate the desired position relative to the parent

  • positioning the parent at 0,0,0, then instantiate all objects, then move it again to wherever it was.

Your choice.

Comment
Jacho_Mendt

People who like this

1 Show 3 · 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 Jacho_Mendt · Feb 01, 2019 at 07:15 PM 0
Share

The first option worked like a charm, but now I'm curious, why using position instead of localPosition didn't work? I thought it'd be fine.

Thank you for your answer tho, it helped a lot!

avatar image bpaynom Jacho_Mendt · Feb 01, 2019 at 08:16 PM 0
Share

The values shown in the inspector are localPosition values. One way to see the world values of an object is to unparent it, so the "parent" of that object is the scene. Then, those X,Y,Z values are world position values. I know at first is a bit confusing, but it's the way most 3D softwares work.

avatar image Jacho_Mendt bpaynom · Feb 02, 2019 at 09:48 AM 0
Share

This makes so much sense now, I didn't know that at all. Thank you!

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

151 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 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

Object with many children will not show up in the center although its coordinates are set to 0, 0, 0 1 Answer

Kinematic Child Object Jumping Above Player 1 Answer

Setting parent in instantiated class 3 Answers

object relative to another object, from its own position 0 Answers

Parent transform not following child transform 0 Answers


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