Hi, I need to spawn new copies of an object from an inactive layer (ok) on several owners if their property changes (ok)
and need to ‘communicate’ with each instance of the object individually (not ok)
as far as I know the added objects share the same GE OBname… so if I send a message everyone receives it. mmmmrrhh. moreover how to control each object properties ?
how can I work with each instance of an added object ?
as I don’t want to duplicate my source object into a billion of copies, so I tried this :
if GoSpawn :
object = Blender.Object.New('Mesh','OriginalObj')
sce = Blender.Scene.GetCurrent()
print "*** %s" % object.getName() # ok : objects 001, 002, 0xx createdon layer 1
helper_add.setObject(object) <b># bug</b>
print "*** %s" % helper_add.getObject()
TypeError: Expect a KX_GameObject, a string or None at line #bug
that’s strange to me as the actuator accepts blender object name (without OB) as argument.
don’t work either.
It looks like you may be mixing in stuff from the Blender module. Also, you could create a list of all the objects:
gl = GameLogic
if not hasattr(gl, "init"):
gl.spawnList = 
gl.init = 1
addObject = gl.getCurrentController().getActuator("spawn")
Also, I don’t see where “helper_add” is set.
ok I’ve found a way through complicated things that lead me to simplicity 4-5 hours later…
useful for example if you spawn the same object from different owners with an addobject actuator, and that you’d like to end JUST ONE of the spawned object, not all of them (as they share the same name).
the name of the spawn is changed to a unique name just after its creation. in this case I’ve added the owner name to the original name.
so for each spawn and not all of them, you can work with everything configured in the original object (brick, props etc…). for example send a message just to one of the spawn, with the dedicated spawn name as subject.
spawn=one of the created object
if my_sensor.isPositive() :
elif o.spawnname == "wait" :
o.spawnname=spawn.name # useful for my purpose
simple. looking at the preview I’m wondering if you won’t laugh at me to post that… but it took me hours to find a way to control ONE spawned object not all of them, so if it can help…
I saw another way by parsing ALL the GE object and change their name if needed, but I think this way is more efficient in this case.
you can’t put it just after the add_actuator :
see http://blenderartists.org/forum/showthread.php?t=141469&highlight=getLastCreatedObject() (#10)
also thank you Social for your posts
thanks Moguri, I didn’t see your post as I was writting mine.
I think the list will contain x times the same object name, so it’s not useful.
The list wouldn’t store the objects name, but rather the instance of the object ;). You could use a dictionary to make it easier to sort through, but I’m not sure what you’d have as the key. But it seems like you got something that works for. Congratulations on figuring it out yourself :yes:
hey thanks. blender is a great way to learn python.
in fact I tried things with an oblist but blender freezes at some point when listing contents, and I saw the same object name repeated… I’ll try again.
You can change the objects name once its added with act.getLastCreatedObject.name = “OBnewname”
You could even use some string formatting to continue the incrementing numbers after the name. If you want some help with that just post.
thanks, I’ve found my way now. but if you know something about that :
be my guest !
I don’t know about that problem but I ran a test and the position is of the added instance not the original object.