Adding a new object with specified location

hi,
i wanna add an object certain location i want. i can add new objects with using addObject script. but i want each new object must be added specified location. is there a way for this.

thanks…

sure
either you move the object there after adding
or you move the emitter there before adding

hi monster thanks for reply. i know i can move the object after addinbg but the thing is in my code i must add a new object each time the button pressed. so when i move the objet it move thie first object added. all new objects named “newobject” but it only moves first object. but i want it moves last object i added.


s.objectsInactive["emitter"].worldPosition= s.objects["replaced_obj"].worldPosition #i tried move the emitter as you sad but no chance
s.addObject(s.objectsInactive["emitter"], s.objects["empty"])
            
s.objects["replaced_obj"].setVisible(False, True)
s.objects["newobj"].worldPosition = [1,0,8] # i tried here moving after adding, yes it works when only one object added but when added a new one it moves first object (cos both obj has same name i guess). but i want last object moved.

maybe i must explain my work to a clear view:
in here i have a floor half side on x+ axis and half of it on x- axis. there is a column object. and when user press add “+ side” button column must move (1,0,0) coordinates. if user press add “- side” column must move (-1,0,0). and when user press “test gravity” button column must replaced with a new rigid body object. it is ok when adding the colum in both sides, but when i added the column on - axis and clicked test button new object appeares in (1,0,0) coordinates.

The addObject return a KX_GameObject which is the added object, so use somenthing like this:

addedObject = scene.addObject("object name", "base object")

And then you can access to the object using “addedObject”, as change the worldPosition:

addedObject = scene.addObject("object name", "base object")
addedObject.worldPosition = [0, 0, 0]

This relies too much on names rather than objects. After addObject the names are not unique. Therefore you need to perform areal search rather than the dictionary access which does not work in that situation.

As carlo697 shows you already get the reference of the added object. You should get no problem to work with that.

As you work with another object"replace_object" you need to find a way to access that one without relying on the name too (unless there is only one).

it works, thanks…