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 :
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.
helper_add.setObject(object.getName())
helper_add.setObject(“OB”+object.getName())
don’t work either.
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.
o=owner
spawn=one of the created object
if my_sensor.isPositive() :
[....]
add_actuator.setObject('original_object')
GameLogic.addActiveActuator(add_actuator, 1)
o.spawnname="wait"
elif o.spawnname == "wait" :
spawn=add_actuator.getLastCreatedObject()
spawn.name=spawn.name+o.name
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.
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.