Weird script behavior

Hello All,

I’m experiencing a strange behavior from a script :

tempPlanetMesh.GetComponent<Transform> ().localPosition = new Vector3 (PlayerPrefs.GetFloat ("PlanetMesh" + SaveSunNb + planetn + "posX"), 0, PlayerPrefs.GetFloat ("PlanetMesh" + SaveSunNb + planetn + "posZ"));
Debug.Log(PlayerPrefs.GetFloat ("PlanetMesh" + SaveSunNb + planetn + "posX"));
Debug.Log(tempPlanetMesh.GetComponent<Transform> ().localPosition);

The script is executed when a key is pressed.
Each time the script is executed, the Debug.Log show the correct value of PlayerPrefs.GetFloat (“PlanetMesh” + SaveSunNb + planetn + “posX”), for example 4000.
and the values of tempPlanetMesh.GetComponent ().localPosition shown in the second Debug.Log are ok (4000,0,whatever).

However, the position of tempPlanetMesh is not set as it should and stays equal to (0,0,0) in the inspector.
Even stranger, this seems to occurs randomly as sometimes it works just well.

I really don’t know why the same script doesn’t always give the same results. And why the localPosition is not always applied to the object transform.

Can you help me with this ?

Thank you !

The second debug log seems to confirm that it is setting the position, which means that it must be after that line when it returns to 0,0,0. It sounds like there is another script that is affecting the position of the planet mesh.

If you manually move the object in the scene view, does it still snap back to 0,0,0?

I thought about something like that but no, there are no other script affecting the object.
And yes I can manually move the objects regardless of their position.