Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by boymeetsrobot · Nov 15, 2010 at 11:27 PM · gameobjectchildrenbestpractices

How to transform an empty GameObject that has gameObject children?

I have created an empty gameObject and added child gameObjects from primitives which I reference via a List<>

public class ObjectManager : MonoBehaviour { private List<GameObject> _cubes;

Primitive generation code snippet:-

        for(int i = 0; i < cubesPerRow; i++)
        {
            cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.position = new Vector3(nextX,nextY,0);
            nextX = (cube.transform.localPosition.x + cube.transform.localScale.x) + cubeSpacing;
            _cubes.Add(cube);
        }

This works fine but now I wish to rotate the parent (objectManager) and have all the child cubes affected by this. To reiterate, I want to apply a single transform and have all of the objects move based on their parents transform.

When I apply a single transform to the parent via Update() none of the children move at all, however I can loop through the _cubes collection and apply transforms to them (which is not the desired behavior).

I am used to Flash's parent / child relationships but new to Unity and 3d so hopefully someone can explain the best way to work with Child objects to me going forward.

Thank you.

[EDIT: Here is my Update function]

    void Update()
{
    float amtToMove = 60.0f * Time.deltaTime;
    transform.Rotate(amtToMove, amtToMove, amtToMove * 2);
}

I have also tried with gameObject.transform to no avail.

Comment
Add comment · Show 2
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 Novodantis 1 · Nov 15, 2010 at 11:31 PM 0
Share

What code are you're using to rotate the parent at present? (that causes no movement of the children)

avatar image boymeetsrobot · Nov 15, 2010 at 11:40 PM 0
Share

I have added the Update code to my original post. $$anonymous$$any thanks.

1 Reply

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

Answer by Novodantis 1 · Nov 15, 2010 at 11:46 PM

Ah, I think you need this, on the line after creating the cube primitive:

cube.transform.parent = transform;

Although you are holding the list inside this entity, created objects are not part of its hierarchy by default.

[EDITED, sorry, its a property of transform not gameobject]

Comment
Add comment · Show 1 · 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 boymeetsrobot · Nov 15, 2010 at 11:49 PM 0
Share

Thanks very much. That did the trick :)

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

1 Person is following this question.

avatar image

Related Questions

Instantiate GameObject, GetComponentsInChildren Cast Type Error - JS 1 Answer

How to check parent value instead name value(more details in post) 3 Answers

Destroy Child Object(s) OnValidate? 6 Answers

Destroy created children of objects 1 Answer

When loading scene, reset GameObject references.. 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