Cannot set Text correct to a spawned TextObject

hi,
since many years i am coming back to UPBGE, and maybe i am getting something wrong after the years.

The Propblem:

I have build a script that should spawn a bunch of faders to adjust different parameters in the simulation i am working on.
The faders do their job well, if i make them inside blender by hand. BUT:
I need to spawn them because, there will be a lot of faders.
I came up with a Fader-function:

> def fader(cont):
> 	own = cont.owner
> 	alw = cont.sensors["Always"]
> 	mo = cont.sensors["MouseOver"]
> 	lb = cont.sensors["MouseLB"]
> 	
> 	if alw.positive:
> 		text = [i for i in own.children if "Text" in i.name][0]
> 		text["Text"] = own["title"] + str(round(own["value"],1))
> 		
> 	if mo.positive:
> 		if lb.positive:
> 			x,y,z = mo.hitPosition.x,mo.hitPosition.y,mo.hitPosition.z+0.2
> 			fader_display = [i for i in own.children if "fader_display" in i.name][0]
> 			fader_display.worldPosition = (own.worldPosition.x,y,z)
> 			own["value"] = own.getDistanceTo(fader_display)
> 			if str(own["target"]).startswith("ob") or str(own["target"]).startswith("G."):
> 				exec(str(own["target"]) +" = " + str(own["value"] ))
> 			else:
> 				exec(str(own["target"]))

so far so good, works as it should.

Then i wrote a SceneBuilder Script:


def createFader(cont,obj_to_spawn,title_,target,value,position):
	own = cont.owner
	#create object
	obj = sce.addObject(obj_to_spawn,own,0.0,False)	
	obj.worldPosition = position
	obj["target"] = target
	obj["value"] = 0.0
	obj["title"] = title_
	
	return obj
	
def main(cont):
	alw = cont.sensors["Always"]
	if alw.positive:

		f = createFader(cont,"Fader","Mass","ob['Mouse']['mass_']",0.0,(-480.911,-264.143,0.0))
		f1 = createFader(cont,"Fader","Grav","ob['Mouse']['grav']",0.0,(-420.911,-264.143,0.0))

This works.

The Problem NOW with the Text

when i click on one of these faders, always every Textobject shows the same, does not matter where it is parented to, and also the controller is(should) not be the same. It is like they are the same object instead of individual ones.
I tried then to check out, with id(): they have unique id’s—
I tried a lot. It almost seems like a bug: when ever you spawn a Text object it is not working like it should…works fine prebuild in blender!
Maybe i am getting it wrong, misunderstood something… is there any paramater i need to set up in blender to make the spawned text unique ??
Thanks for your help!
Or any dirty workaround to fix it ?
somethong like reinstanceMesh or similar?
I have tried the “Instancing” Parameter in blender, but no change in behaviour.
I even tried to unparent the text from the Plane it is attachet to, and setParent() in realtime-- no change–

Any Ideas?

thanks to BluePrintRandom, there is a workaround.
needs to add:


obj.children["Text"].blenderObject.data = obj.children["Text"].blenderObject.data.copy()

to the code to make a real copy of the KX_TextObject.

Problem Solved!

1 Like