UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.43k stars 180 forks source link

KX_FontObject["Text"] not set correct on spawned objects #1792

Closed sevi78 closed 1 year ago

sevi78 commented 1 year ago
          I just found out, that whenever one adds a KX_FontObject with python or Actuator, the text assigned is always on all instances of the KX_FontObject---makes it impossible to assign text in realtime to spawned Texts. ... or i might be dumb as a donkey :) 
import bge
G = bge.logic
sce = G.getCurrentScene()

t = sce.addObject("Text",own,0.0)
t.worldPosition = (-2,0,0)
t["Text"] = "text"
## so far so good, t["Text"] shows "text"

## now after adding another Text, t["Text"] shows "text2"
t1 = sce.addObject("Text",own,0.0)
t1.worldPosition = (0,0,0)
t1["Text"] = "text2"

i have also tried with instantAddObject and Actuators with the same result

Originally posted by @sevi78 in https://github.com/UPBGE/upbge/issues/1297#issuecomment-1426930460

BluePrintRandom commented 1 year ago
import bge
G = bge.logic
sce = G.getCurrentScene()

t = sce.addObject("Text",own,0.0)
t.worldPosition = (-2,0,0)
t["Text"] = "text"
## so far so good, t["Text"] shows "text"

## now after adding another Text, t["Text"] shows "text2"
t1 = sce.addObject("Text",own,0.0)
t1.data = t1.data.copy()
t1.worldPosition = (0,0,0)
t1["Text"] = "text2"
sevi78 commented 1 year ago

Thanks so much !! you are my hero! but:

AttributeError: 'KX_FontObject' object has no attribute 'data'

BluePrintRandom commented 1 year ago

oh sorry

t1 = sce.addObject("Text",own,0.0)
t1.blenderObject.data = t1.blenderObject.data.copy()
t1.worldPosition = (0,0,0)
t1["Text"] = "text2"

KX_Object.blenderObject is the bpy.data.objects ob the KX_Object is 'wearing'

sevi78 commented 1 year ago

works !!! thanks ! i mean its a workaround, would be nice to have the behaviour like a KX_GameObject. Buts its fine for me

BluePrintRandom commented 1 year ago

if we edit a mesh, all copies 'wearing' the mesh are effected.

so it is the same really, but instead of editing a mesh we are editing a text object,

the blender text object can do all sorts of fancy stuff using KX_Font.BlenderObject.data.curves I believe. (like set the text to use multiple materials)