Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Strange lighting due to inconsistent Z-position after setting parent

Discussion in 'AR' started by rajshirolkar, Jul 16, 2020.

  1. rajshirolkar

    rajshirolkar

    Joined:
    May 17, 2020
    Posts:
    2
    I'm making an Android AR app and I'm trying to augment a few gameobjects on a glass plate in AR. For this i have a plate game object and I'm trying to place the child gameobjects on that plate by making the plate as parent. But when I set the plate as parent of child the child objects have inconsistent z position even if I try to set its z position as the z position of parent explicitly.

    1. I set the x&y positions of the child and set its Z to the parent's z
    child.transform.position = new Vector3(x_pos, y_pos, parent.transform.position.z);

    2. I set the plate as the parent of child and log their positions before setting parent and after setting parent
    Code (CSharp):
    1. Debug.Log("Parent Z value : " + parent.transform.position.z);
    2. Debug.Log(" Before setting parent, Child Z value : " + child.transform.position.z);
    3.  
    4. child.transform.SetParent(parent.transform, true);
    5.  
    6. Debug.Log(" After setting parent, Child Z value : " + child.transform.position.z);
    3. The logs I got had Z value different after setting parent which shouldn't happen as child and parent both have had the same Z-values since their instantiation :

    -> Parent Z value : 0.2666564

    Before setting parent, Child Z value : 0.2666564

    After setting parent, Child Z value : 0.308827


    The changed z value also is different for all the child objects. This is causing the gameobjects to light up randomly when I move my phone camera around.
     
    sneharakhonde likes this.
  2. sidbhise

    sidbhise

    Joined:
    May 13, 2020
    Posts:
    7
    I see a similar issue, but not sure it this is happening because of the z-axis or lighting in the scene.