How to get an object to spawn at a specific location?
How would one spawn an object at a specific location?


Adding new objects (basically making a copy of an inactive object) requires a reference object. The new object will inherit the transformations (location, orientation and scaling) from the reference object, rather than from the template object (the inactive object which resides at a hidden layer).

AddObject Actuator

The AddObject Actuator uses the owner as reference object. The owner is the object the actuator is configured of.

This means when you have an empty with an AddObject actuator, this empty will be the reference object while you select the template object at the actuator itself (field: Object)

Python API

The python call KX_Scene.addObject() request you to provide a template object as well as a reference object. The call should be from the scene both objects live in.

Solution

The conclusion is quite simple:

1) place the reference object at the desired location (e.g. an empty)
2) add the new object

(alternative Solution) Post processing

In some situations it might be not sufficient to relocate a reference object (just now I can't think of such a situation). In this case you can add the new object anywhere and relocate it afterwards, just by assigning a new location.

Be aware this can have side effects on physics calculations as right after creation the object will be considered as present.

Setting object Position via Python

Use attribute KX_GameObject.worldPosition. 

Examples:

import mathutils

position = mathutils.Vector([0, 1, 0])
gameObject.worldPosition = position


You can even use a list.

gameObject.worldPosition = [0, 1, 0]