I am having trouble activating an inactive gameobject using SetActive() & then changing its Transform, during the same frame.
GOB.SetActive(true);
GOB.transform.GetChild(0).localPosition = new Vector3(0, 0, 0);
GOB.transform.GetChild(0).localScale = new Vector3(1, 1, 1);
Here is a step-by-step of what happens.
Debug.Log("Setting Active & localPosition & localScale");
GOB.SetActive(true);
Debug.Log("Name: " + GOB.transform.GetChild(0).name);
Debug.Log("localPosition: " + GOB.transform.GetChild(0).transform.localPosition);
Debug.Log("localScale: " + GOB.transform.GetChild(0).transform.localScale);
GOB.transform.GetChild(0).localPosition = new Vector3(0, 0, 0);
GOB.transform.GetChild(0).localScale = new Vector3(1, 1, 1);
Debug.Log("new localPosition: " + GOB.transform.GetChild(0).transform.localPosition);
Debug.Log("new localScale: " + GOB.transform.GetChild(0).transform.localScale);
- Log: Function was Called
- The GOB is set as active right when this is called.
- Log: Correct GOB is being altered.
- Log: Old Position is correct (y = 50)
- Log: Old Scale is correct (xyz = 1.2)
- y = 0
- xyz = 1
- Log: New Position is correct (y = 0)
- Log:New Scale is correct (xyz = 1)
- Actual Transform is Old Position, Old Scale
- On NEXT FRAME, GOB has New Position/Scale
I had the same problem when Instantiating GameObjects. They would Instantiate at one position, then not update until next frame. This causes the Unity UI icons to warp/flicker (ugly animation- the player can notice this happening).
To fix this when Instantiating, I simply used Instantiate(GOB, NewPosition), avoiding setting the Position entirely.
However I can’t do this when activating a GOB with SetActive().
I don’t believe I used to have this problem with Unity (ex. Unity 4).
Currently using Unity 5.3.6f1.