Positioning GameObject after instantiate shifts origin instead of moving GameObject

Hi,

I am instantiating a GameObject (called BattleStation) and then attaching it to a parent (the GameObject acting as the parent of the whole scene). After this I then try to position the BattleStation GameObject using transform.position but the BattleStation does not move but adjusts it’s origin point by the amount that is supposed to be moved. Is this normal behaviour?

The code for this is:

using UnityEngine;
using System.Collections;

public class EntryPoint : MonoBehaviour
{
	GameObject playerBase;

	void Update()
	{
		if(playerBase == null)
		{
			playerBase = (GameObject) Instantiate(Resources.Load("BattleStation"));
			playerBase.transform.parent = gameObject.transform;
			playerBase.transform.position = new Vector3(15f, 0f, 0f);
		}
	}
}

The white line in the image represents the origin point of the scene (0, 0, 0), and the red line represents the origin point of the BattleStation GameObject. Notice that it is not at the centre of the GameObject where it should be and that it has moved 15 units on the x-axis.

Now if I wait a frame then re-position my BattleStation GameObject then it works as expected.

using UnityEngine;
using System.Collections;

public class EntryPoint : MonoBehaviour
{
	GameObject playerBase;

	void Update()
	{
		if(playerBase == null)
		{
			playerBase = (GameObject) Instantiate(Resources.Load("BattleStation"));
			playerBase.transform.parent = gameObject.transform;
		}
		else
		{
			playerBase.transform.position = new Vector3(15f, 0f, 0f);
		}
	}
}

In this image the BattleStation has moved 12 units in the x axis while its origin point has remained at the centre of the GameObject. This is what I expect the first bit of code should have done.

So my question is should re-positioning a GameObject after instantiation move it’s origin point instead of actually moving the GameObject itself?

The “origin” is the position of your object, there is only one position per object. Do you have dynamic batching enabled (don’t know if its pro only)?
You can’t move already batched static meshes around. Just click on the mesh in the scene view and see if the name changed to something else than the original name.

If the object is a child of another I think you might get the result you want if you change localPosition rather than position.

Found the issue and solved it.

I had script on BattleStation where it was building the battle ship out of cubes and I wasn’t setting each Cubes position to be based off where local position of the BattleShip (it was done from (0, 0, 0)).

A silly mistake, sorry for your time.