Problems with Spawned Objects

i’ve got everything set up and working in my extended game demo for Urban Decay (details in WIP), but i decided that instead of having one of the main characters pre-loaded in the scene, it should be spawned into the scene if no character currently exists

i use the Edit Object/Add Object actuator to do it, and it all works fine

however (and there always seems to be a “however”) - one mechanism i use in the character’s script is “getDistanceTo” to check how far away the other character is

but the spawned object shows this as being permanently zero (i’ve tried “getVectTo” and that has the same problem)

anyone got any ideas or suggestions?

EDIT: the “position” of the other object seems to be obtainable ok, so i guess i’ll just have to write my own “DistanceTo” routine…

Maybe post a simplified blend showing the problem occuring… it could be a bug… if it an actual bug the devs need to know about it.

hmmm…

when i tried to set up a small demonstration, i found that the problem’s actually a little different to what i originally thought

if i print the values out, they look good

but… if i try and load the value into a property and display it via the debug options (which i often do because it’s sometimes handier to see them updated in real time, than having to go to the console later), it’s THEN that the value is always displayed as zero

in other words, i think the bug’s in… the debug display… and not where i originally thought

i think

i’ll do a little more experimenting before i raise an error report though

Not really. If you use addobject you create a new instance of the object. I think the display shows the values of the hidden (and inactive) “master” object not the values of the new instance.

If you have more instances you will not see the debug information of the other instances either.

yeah, i guess that makes sense

one thing i’ve not figured out yet is how to refer to new instances of a master object from within code

actually that was today’s question, so i may as well ask it here…

EDIT: answered my own question by spawning objects into a scene and printing out objlist() each time, and… each object seems to come into the scene with the same name

which means, i guess, that you simply can’t refer to individual instances of the object?

EDIT2: AH! that probably also explains why an “End Object” actuator destroys ALL instances of the object too…

EDIT3: Sooooooo… next question: how do i destroy an individual instance of a spawned object?