0
\$\begingroup\$

So z position on some gameObject being generated from a prefab was being set wrong. I create to function to do like a reset transform thing, but when I set the localPosition in the function it does not reflect in the transform localPosition.

Bellow is a copy and paste out of a function and what follow is two function that set the transform, and how I log the data and what it show:

        renderGT.ResetGmObjTransforms(image);
        image.transform.localPosition = new Vector3(0,0,0);
        Debug.Log("image: "+image+" image.transform: "+image.transform+
        " image.transform.position: "+image.transform.position+
        " image.transform.localPosition: "+image.transform.localPosition);//DEBUG.LOG::: image: Image (UnityEngine.GameObject) image.transform: Image (UnityEngine.RectTransform) image.transform.position: (2.2, 1.9, 91.0) image.transform.localPosition: (0.0, 0.0, 0.0)


public static void ResetRectTransform(RectTransform rectTran){
    // rescale
    rectTran.localScale = new Vector3(1f,1f,1f);
    // position
    rectTran.position = rectTran.localPosition = new Vector3(0f, 0f, 0.0f);
    // rotate
    rectTran.rotation = rectTran.localRotation = new Quaternion(0, 0, 0, 1);
}

public static void ResetTransform(Transform tran){
    // rescale
    tran.localScale = new Vector3(1f,1f,1f);
    // position
    tran.position = tran.localPosition = new Vector3(0f, 0f, 0f);
    // rotate
    tran.rotation = tran.localRotation = new Quaternion(0, 0, 0, 1);
}

public static void GameObjectResetTransform(GameObject gmObj){
    // rescale
    gmObj.transform.localScale = new Vector3(1f,1f,1f);
    // position
    gmObj.transform.position = gmObj.transform.localPosition = new Vector3(0f, 0f, 0f);
    // rotate
    gmObj.transform.rotation = gmObj.transform.localRotation = new Quaternion(0, 0, 0, 1);
}

public static void ResetGmObjTransforms(GameObject gmObj){
    ResetRectTransform((RectTransform)gmObj.transform);
    ResetTransform(gmObj.transform);
    Debug.Log("gmObj: "+gmObj+" gmObj.transform: "+gmObj.transform+
    " gmObj.transform.position: "+gmObj.transform.position+
    " gmObj.transform.localPosition: "+gmObj.transform.localPosition);//DEBUG.LOG::: gmObj: Image (UnityEngine.GameObject) gmObj.transform: Image (UnityEngine.RectTransform) gmObj.transform.position: (0.0, 0.0, 0.0) gmObj.transform.localPosition: (-1747.4, -113.6, -5174.5)
    GameObjectResetTransform(gmObj);
    Debug.Log("After GameObjectResetTransform(gmObj): gmObj: "+gmObj+" gmObj.transform: "+gmObj.transform+
    " gmObj.transform.position: "+gmObj.transform.position+
    " gmObj.transform.localPosition: "+gmObj.transform.localPosition);//DEBUG.LOG::: After GameObjectResetTransform(gmObj): gmObj: Image (UnityEngine.GameObject) gmObj.transform: Image (UnityEngine.RectTransform) gmObj.transform.position: (0.0, 0.0, 0.0) gmObj.transform.localPosition: (-1747.4, -113.6, -5174.5)
}

As you can see the Debug Log on log the very last change done to the transform correctly. For some reason when it set in one of those function it doesn't set which the other two debug log show. Any ideals to why this is happening?

\$\endgroup\$
  • \$\begingroup\$ I am not understanding your question. \$\endgroup\$ – Draco18s Feb 6 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.