• 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
1
Question by Lucky_Mike · Nov 20, 2014 at 11:01 PM · parent and child

Placing child object on parent objects local-space origin

I've imported a single model, which is composed of dozens of different mesh. Each mesh is uniquely selectable in the unity editor, but all of them are attached to the parent gameobject. If I select one of the child mesh and look at it's transform, it's position will be (0,0,0). That makes sense based on my understanding that the transform of a child gameobject is relative to the origin of the parent's transform.

Let's say the model is a pool table. I place the model at the exact world origin, (0,0,0) The pool table has 7 child gameobjects each with their own mesh. Six of these mesh are the six standard holes in a pool table, and the remaining mesh is everything else. What i'd like to do is now create a new gameobjec, lets say a generic spherical mesh, who's parent is one of these holes, and have it's location be pretty much wherever that hole mesh is located. What's happening is that the new gameobject, who's parent is one of said holes, and has a location of (0,0,0), is being placed at the bottom left corner of the entire table and not anywhere near the parent hole mesh as I'd have expected. I'd like to be able to create a new prefab gameobject and drag it as a child object of each of the six holes, and have each new object be located where their parent hole mesh is.

Comment
Add comment · Show 1
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 MrSoad · Nov 20, 2014 at 10:56 PM 0
Share

I've done something similar with a pool table, I put the individual mesh parts anchor points at their own individual centers, then when I placed objects via scripting I used their individual origin points as base placement vectors.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 21, 2014 at 12:44 AM

If your child objects (the holes) have it's origin at the parents origin, why would you expect when setting another objects position to that position that it will be somewhere else? I guess your hole meshes are simply ofsetted in localspace, so their pivot is not in the center of the hole but at the pivot of the parent. When you see 0,0,0 in the inspector it means it's at the same position as the parent is.

If your table and hole meshes are made in an external application you should move the pivots of the hole objects to the hole's center.

Comment
Add comment · Show 4 · 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 MrSoad · Nov 21, 2014 at 12:46 AM 0
Share

Yep this is about where we have got up to, do you know how to do this in sketchup at all, I have no idea, I always use Blender. Thanks Bunny83 :)

avatar image Bunny83 · Nov 21, 2014 at 02:53 AM 0
Share

@$$anonymous$$rSoad: No, sorry :D I'm not an artist. The only visual tools i've ever used are $$anonymous$$SPaint, some Photoshop / Paint .NET / Gimp, Worldcraft(aka Hammer) and Unity :D I had a short course on 3ds max but forgot almost everything. I tried blender a couple of times but i always come to the conclusion that i'm not made for modelling ^^. I know more about how those tools work behind the scenes than how to use them.

avatar image MrSoad · Nov 21, 2014 at 03:23 AM 0
Share

No problem, just thought I would ask, you seem to know a lot! Thanks anyway :D

avatar image Lucky_Mike · Nov 21, 2014 at 03:10 PM 0
Share

Turns out this is not so easily done in sketchup. Searching google, it's quite a common issue people have with sketchup and none of the "workarounds" are very appealing. I've opted to go over some basic blender tutorials ins$$anonymous$$d. Thanks for the help everyone!

avatar image
0

Answer by Jeff-Kesselman · Nov 20, 2014 at 11:02 PM

http://docs.unity3d.com/ScriptReference/Transform-position.html

Set your new object's root's position to the hole's position.

Comment
Add comment · Show 9 · 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 Lucky_Mike · Nov 21, 2014 at 12:06 AM 0
Share

In this case, that doesn't seem to work. ie: transform.root.position = GetComponentInParent().position;

I also tried just using transform.parent.position to no avail. Are my issues perhaps related to the fact that all mesh are really a part of a single model which I've imported?

avatar image MrSoad · Nov 21, 2014 at 12:13 AM 0
Share

Do all your individual mesh components of the model share one single anchor point location(at the bottom left hand corner of the table) ?

avatar image Lucky_Mike · Nov 21, 2014 at 12:21 AM 0
Share

I don't believe that's the case, as I'm able to rotate each mesh individually along it's own axis. Also, each mesh is in a different location but all have identity as their transform matrix.

avatar image MrSoad · Nov 21, 2014 at 12:27 AM 0
Share

If you have Unity's tool handle set to "center" rather than pivot then it will rotate around the mesh center rather than it's pivot(anchor) point, double check this by doing this when it is set to pivot if you have not already.

avatar image Lucky_Mike · Nov 21, 2014 at 12:35 AM 0
Share

$$anonymous$$rSoad you're correct. I was indeed set to to "center" and upon switching over to "pivot" I can confirm that all objects have a single pivot point in the corner. I'm not exactly a 3d modeler and I had just whipped up this simple model in Sketchup and imported it into unity. Is there any way to move the child mesh to the center of the parent mesh, ins$$anonymous$$d of the pivot?

Show more comments

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

6 People are following this question.

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

Related Questions

Parent and childs 1 Answer

Destroy child with Particlesystem will cause error 1 Answer

How to disable player gravity 2 Answers

How to get my child objects to follow the parent? Also, not sure if this is working. 0 Answers

Im trying to a child object follow the path of the parent in the path that the parent has already traveled... 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