Within Start() I am instantiating a prefab several times along the z axis . I.e. the z-position is increased for each new instance of the prefab. Strangely the LAST instance is instantiated at the FIRST z position when I start the game.
Details:
In Start() I am running this loop
_createPosition = new Vector3(0, 0, 0);
for (_parcelCounter = 1; _parcelCounter <= 7; _parcelCounter++)
{
_createPosition = CreateParcel(_createPosition, _parcelCounter);
}
Within the function CreateParcel() the z position is increased, an instance of the prefab is instantiated at this z position and the name of the instance is changed (`PrefabInstance.name = "Instance " + parcelCounter;`). The function looks (simplified) like this:
Vector3 CreateParcel(Vector3 parcelPosition, int counter)
{
parcelPosition.z = parcelPosition.z + 5;
Instantiate(ParcelPrefab, parcelPosition, Quaternion.identity);
ParcelPrefab.name = "Instance " + counter;
return(parcelPosition);
}
When I log the data with `Debug.Log("Instance " + counter + ": " + createPosition)` I get the following output when I run the scene:
Log results: Instance 1: (0.0, 0.0, 5.0) Instance 2: (0.0, 0.0, 10.0) Instance 3: (0.0, 0.0, 15.0) ... Instance 7: (0.0, 0.0, 35.0)
But when I check the instances in the scene hierarchy, the instances don't match this sequence. When I check the position of the different instances with the Inspector it is the following sequence:
Inspector results Instance 1: (0.0, 0.0, 10.0) Instance 2: (0.0, 0.0, 15.0) Instance 3: (0.0, 0.0, 20.0) ... Instance 7: (0.0, 0.0, 5.0)
That is ... (the logged) instance 7 is not at the end of the sequence as it should be and as the log said, but it is in the first position of the sequence. Where does this difference come from? Or is there any silly error in my thoughts/script?