Search Unity

Question how to prevent Parent location to be manipulated by childs objects location

Discussion in 'Scripting' started by kader1081, Mar 12, 2023.

  1. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    bus.png dus.png View attachment 1211400 View attachment 1211403 Hi there is a empty gameobject and has about 30 child and every one of them has different location.Problem is when parent location is shown 0 0 0 actually isn't when I try to ınstatiate or move a object by parents transform location. Location is wrong
     
    Last edited: Mar 13, 2023
  2. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    494
    I'm not sure if I understand what it is that you're asking. Parent locations are not manipulated by child objects unless a script specifically does that. I'm guessing you're trying to set a child objects transform location relative to the parent? To do that you would use localPosition.
    https://docs.unity3d.com/ScriptReference/Transform-localPosition.html
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,930
    This isn't really how transform hierarchies work. The child's position is dependant on the parent, not the other way around.

    Do note that the inspector shows a transform's local position, not it's world position. So if this 'parent', is the child of something else, it is probably (0, 0, 0) local to its parent.
     
  4. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    this 2 objects have different tranform.position but they are in the same location
    bus.png dus.png
     
  5. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    I uploaded 2 pics 2 objects which both of them are parent has different tranform.position and they are on the same spot.
     
    Last edited: Mar 13, 2023
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,930
    The transform handle in your image clearly demonstrates they are in different physical positions.
     
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,004
    You have set your gizmos mode to center, not to pivot. In really rare situations center may be useful. However you should keep the gizmos mode to pivot and local whenever possible.

    This does not change the position of the objects, just where and how the gizmos are displayed.
     
    kader1081 likes this.
  8. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,004
    Just in case you don't know what I'm talking about, it's about those two settings:
    upload_2023-3-13_10-1-45.png
     
    kader1081 likes this.
  9. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    same tranfrom.position different location
    deys.png heys.png
     
  10. kader1081

    kader1081

    Joined:
    Oct 16, 2021
    Posts:
    379
    Thank you so much it worked I have been struggling about hours since yesterday