Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 justinc847 · Jun 08, 2017 at 02:09 AM · scripting probleminstantiateinstantiating

Change position of instantiated parent's children

I have alot of gameobjects that are all children of an empty gameobject, and after colliding with a trigger, I need to instantiate all of those gameobjects and adjust their position. If I instantiate the parent object, as according to the scripting api, the children will take the position of the original object instead of where i position the new parent. How do I fix this? This is my current line of code

 Instantiate(spawn, new Vector3(0, 0, currentZ + 103), Quaternion.identity);

but since I am instantiating a parent object that is empty, all of the children do not take the new position. Any help is greatly appreciated.

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

1 Reply

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

Answer by toddisarockstar · Jun 08, 2017 at 02:50 AM

No actually.

when instantiating a gameobject, the fact that it is an "empty" is irrelevant. (empty game objects still have a transform). so if you instantiate an empty gameobject with children attached, The children will spawn with the same parenting, and appear in relation to where the new parent is spawned. if you want the new children in different places you simply change their position to where you want after the instantiate.

Children always follow the parent. empty gameobjects still have transforms and follow all the parenting and positioning rules just like spawning any other model or rig.

if you need a code example for moving children let me know!

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 justinc847 · Jun 08, 2017 at 05:08 PM 0
Share

Hmm. So basically what your saying is they should be following my parent object anyway? I tested it with a cube that i added in to the scene and it worked fine, but it doesnt work with my group of objects. When I read over the api it said the children would take the position of the orginal objects that were cloned, but it did not specify if it was relative to the parent position or if it was hard cooridinates in world space. Based off what your saying it sounds like they should be relative. What could be a reason that it isnt working then? I just assumed it didnt appear to be working because the objects were just spawning at the exact position of the objects that were already in the scene. Whats a way to go about this? And a code sample on moving the children would be great so I can try that too lol.

avatar image justinc847 · Jun 08, 2017 at 05:56 PM 0
Share

Ok so I just looked again at what I was doing, and since I grouped all of these objects my vectors were off, it actually became

 Instantiate(spawn, new Vector3(-205.4885f, -97.14504f, currentZ + 103), Quaternion.identity);

I completely overlooked that and just put zeros since my children were at zero, didn't even think of where my parent object actually was, and like you said, the children were automatically relative to it. Thanks a lot!

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.

Follow this Question

Answers Answers and Comments

113 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

Related Questions

Why does my instatiate crashes editor? 1 Answer

How to make script affect only one this game object 2 Answers

Instantiated Bullets Not Picking Up Correct Position/Rotation 2 Answers

Instantiated clones using each other`s script 0 Answers

Making a shotgun shooting 45 degrees to the left of the mouse 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