Why does the transform.position not trigger

I have a problem i do not understand with this code:

for (int indxFinal = 0; indxFinal < finalChangedCard_List.Count; indxFinal = indxFinal + 6) {

            float finalX         = float.Parse(finalChangedCard_List[indxFinal + 1]);
            float finalY         = float.Parse(finalChangedCard_List[indxFinal + 2]);
            float finalZ         = float.Parse(finalChangedCard_List[indxFinal + 3]);
            float finalTWIST     = float.Parse(finalChangedCard_List[indxFinal + 4]);
            int finalSortOrder    = int.Parse(finalChangedCard_List[indxFinal + 5]);

            print ("X: " + finalX + " Y: " + finalY + " finalZ: " + finalZ);

            dummyGO = GameObject.Find(finalChangedCard_List[indxFinal]);
            print ("dummyGO.name: " + dummyGO.name);

            dummyGO.transform.position = new Vector3(finalX, finalY, finalZ);
            dummyGO.transform.localEulerAngles = new Vector3(0f, 0f, finalTWIST);
            dummyGO.GetComponent<Renderer> ().sortingOrder = finalSortOrder;

    }

Nothing is executed after this code that can change the positions. The output is:

X: 2.959876 Y: -1.832011 finalZ: 51
dummyGO.name: H8_1B

But the object “H8_1B” does not move to the position printed. I tested “dummyGO.SetActive(false)” and that worked???

Situation after the code is executed, position is still the initial one:

Is it possible there’s some other script overriding the position?

I have been looking at that but cannot find any. The fact that i can disable the game object means that i do get the reference. I am trying to find anything but still do not understand what is happening.

Can you move the object manually (i.e. change its position in the inspector or scene view) when this script is failing to set its position?

Yes i can.

I added a coroutine that i called on:

IEnumerator xyz() {
        yield return new WaitForSeconds (0.0f);

        RepositionToFinalPositions ();
    }

And now suddenly it works. The coroutine waits for 0 sec so i do not understand the difference, totally puzzled. …but it works :slight_smile:

The way i do it is that i have a function, called prior to this, that re-instantiate all objects to original positions and then, directly after, call the function with this code. I guess there is some sort of crash between them???

Thanks for helping me!

It’s likely that due to script execution order, something else was being run immediately after your positioning code (in the same frame) that was undoing their positions. Your new code is causing it to wait 1 frame.

You are probably correct, a BIG thank you for your help :slight_smile: