• 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 /
  • Help Room /
avatar image
0
Question by Fikule · Jun 18, 2016 at 05:49 AM · c#transformparent transform

SetParent changing the relative position of the parent

I feel like this is a bug.

Basically I have two game objects, one at position -7,0,0 and one at 7,0,0

http://i.imgur.com/A3ENwad.png

http://i.imgur.com/UcSeP21.png

These two have a script on them that creates a Tile class script, which in turn creates a GameObject and sets the parent to the first object.

http://i.imgur.com/NBTYa6P.png

(tiles is an array of Tile, but when testing t was 0 and not in any kind of loop. SetSprite alone causes no issues. It is only when SetParent is called. SetParent is the last thing called.)

When the parent is set, the parent objects are moved on screen to the centre, but retain their positions. This means they are still -7,0,0 and 7,0,0 but they occupy the same space on screen.

http://i.imgur.com/ZicSnJ1.png

They have no parents of their own, they are just at different positions while in the same position. I have to move them to -14,0,0 and 14,0,0 to get them back to where they should be. Their positions are completely independent of other objects in the game and I can't see why.

Comment
Add comment · Show 3
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 EpiFouloux · Jun 18, 2016 at 12:15 PM 0
Share

Your script sets the object as parent of itself, are you sure about that?

avatar image Fikule EpiFouloux · Jun 18, 2016 at 01:05 PM 0
Share

@Epifouloux Can you explain? I don't think I do. tiles[t] is an instance of Tile. tiles[t] is in a separate class to the Tile class. It calls SetParent as a function of Tile which then sets the parent on m_sprite, m_sprite is the only object having it's parent set.

avatar image Owen-Reynolds · Jun 18, 2016 at 02:21 PM 0
Share

It's more common to include the important lines of the script as text, inside your question. Often when you test, you simplify to something small that causes the problem, so you can post just that.

Having code in a picture, or as a link, makes it harder for people to read/test what you have. Also, I moved this to the HelpRoom (since it seems like an individual problem, not completely understanding a part of parent/child, or perhaps a bug.)

1 Reply

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

Answer by Fikule · Jun 18, 2016 at 02:28 PM

"Solved" it.

It was simply basing the position of the movement indicator on the child object's position (0). Not sure why though, but it's working at least.

I assume the movement indicator places itself at the average position of all the component (child) pieces?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

reset a GameObject parents childs to 0 if a item has changed its parent 2 Answers

UnityException: Transform child out of bounds (C# Unity) 0 Answers

function behave unexpectedly inside a coroutine. 0 Answers

Coroutine: delay transform rotation but start transform movement immediately 2 Answers

GameObject not changing position in PlayMode although the Transform changes 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