• 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
3
Question by awplays49 · Dec 11, 2014 at 09:58 PM · transformparent

How to transform only a parent and not its children?

How would i do this?

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 RedHedZed · Dec 11, 2014 at 10:00 PM 0
Share

Do the children ever move?

3 Replies

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

Answer by rutter · Dec 11, 2014 at 10:09 PM

Children always move with their parent, but you can compensate for that.

Here's some JS code to demonstrate the rough idea:

 //example movement vector
 var movement = Vector3.one;

 //move whatever object this script is attached to
 transform.position += movement;

 //apply equal and opposite movement to each child
 for (var child : Transform in transform) {
     child.position -= movement;
 }
Comment
Add comment · Show 6 · 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 Kiwasi · Dec 11, 2014 at 10:14 PM 2
Share

While this works. Its worth noting that in general its a bad idea. The whole point of parenting is to make an object move with its parent. You are better off not parenting the object.

There are some specific situations where it may be warranted.

avatar image whisp · Dec 11, 2014 at 10:15 PM 1
Share

This might be a problem with rotation. Another way could be storing the positions and rotations of the children to re-assign them in the next frame.

avatar image RedHedZed · Dec 11, 2014 at 10:23 PM 0
Share

I was going to suggest something similar to whisp. The whole idea of not moving the children with the parent is kind of strange though and I don't think really has an elegant solution.

In general, I would agree with Bored$$anonymous$$ormon.

avatar image awplays49 · Dec 11, 2014 at 10:37 PM 0
Share

See my issue is that i want the health and energy bars of my game to travel with the player but not rotate. @Bored$$anonymous$$ormon @RedHedZed @whisp @rutter

avatar image whisp · Dec 11, 2014 at 10:48 PM 0
Share

@awplays49

You could create it as a separate object and set its position in update() to the player position (+ offset).

Show more comments
avatar image
2

Answer by joergzdarsky · May 28, 2016 at 09:09 AM

I'd like to add a request for this possibility (transform / move parents but not the children). And although you normaly indeed parent objects because they should be grouped and transformed together, this is not always intended - and not related to bad design, thus I wouldnt agree to @BoredMormon and @RedHedZed here.

Here is my usecase: I am using the (commonly used) "Floating Origin" technique for my space game. So, I generally keep my camera close to the origin (0,0,0) for precision reasons. When the camera has moved to a certain distance, I reset the camera to the origin (0,0,0) and move all objects around for the same distance -> Floating Origin.

In that case I have to move a lot of object at once. Extreme situations where I have to move everything each frame is not unlikely. Thus a highly optimized strategy is required for performance reasons.

The way I do it now is to traverse through the children of an object (which is an empty "Space"-Object) and move each object individually by the same distance. The corresponding script (which realized Floating Origin) is attached to the camera:

 [RequireComponent(typeof(Camera))]
 public class FloatingOriginByParent : MonoBehaviour
 {
     public float threshold = 6000.0f;
     public GameObject parentGameObject; // GameObject where all child objects are to be shifted
     void LateUpdate()
     {
         Vector3 cameraPosition = gameObject.transform.position;
 
         if (cameraPosition.magnitude > threshold)
         {
             foreach (Transform child in parentGameObject.transform)
             {
                 child.transform.position -= cameraPosition;
             }
             gameObject.transform.position = new Vector3(0,0,0);
         }
     }
 }

Thats the best you can do in Unity AFAIK, and basically what @rutter suggested, however its still not optimal.

The above results in thousands of single shifts including a large loop, each frame. It would be performance-wise much better if I could group all objects under a "Drag" or "Anchor"-like empty gameobject, that is once shifted (including the children) for the required distance, and then reset to the origin (without the children). Doing that manually is even worse than the above code. However, shifting lots of objects by its parent is faster, but to realize Floating Origin with that you need a function to independently reset the parent.

So an additional function to transform a parent gameobject without the children would be the key here.

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
avatar image
1

Answer by tezza2k1 · Sep 02, 2018 at 08:51 PM

Old post, yet I had the same problem.

.

Some objects were deep in a hierarchy and the parents had x,y,z position would be better if they were at (0,0,0). If you adjust the parent directly to the origin, all the children shift as well.

.

I figured out a way to keep the children in place in the editor.

.

Create a new Empty GameObject as a sibling of the Parent. This will naturally be at (0,0,0).

.

Drag the children into that Empty GameObject. The editor will adjust the coordinates of the children.

.

Save the name of the old parent

.

Delete the old parent.

.

Rename the Empty Gameobject to have the same name as delete parent.

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

29 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

Related Questions

undoing parenting of object's transform 1 Answer

Separate child rotation 1 Answer

Assign parent object to target 2 Answers

How to move the parent object to a child of one of its children? 1 Answer

Object scale/rotation changes when parented to flipped object 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