【发布时间】:2015-07-05 03:22:20
【问题描述】:
我知道有一种方法可以找出特定对象在 BGE 中所在的组。
在 API 中,它说您使用 KX_GameObject(SCA_IObject) 和 groupObject 获取对象所在的组,并使用 groupMembers 获取组中所有对象的列表。我尝试了许多不同的方法来让它工作,但我总是得到一个错误。请问有人能告诉我怎么做吗?
这是代码。
import bge
from bge import logic
import bpy
cont = bge.logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
objs = scene.objects
print(objs)
#here I tried to get the list of members in the group
group = bpy.data.groups["group"]
print(group.groupMembers)
#ERROR: 'Group' object has no attribute 'groupMembers'
#here I tried to get the group object is in
cube = bpy.data.objects["Cube"]
print(cube.groupObject)
#ERROR: 'Object' object has no attribute 'groupObject'
谢谢。
【问题讨论】:
-
您能否详细说明如何您的程序失败了?从文档中,您编写
my_object.groupObject以获取 “对象所属的组对象,如果该对象不属于某个组,则为 None” 这是否引发了异常?你有没有收到None的期待?您确定该对象属于某个组吗?我可以建议你写一个minimal program 来展示你的问题吗? -
我添加了代码。感谢您重播。
-
group可能(也许?)不是KX_GameObject实例。尝试通过添加print(type(group))、print(group)、print(group.__dict__)之类的内容来更仔细地检查您的group(respcube) 对象。 -
最真实的我......我尝试了一个小时,然后在堆栈溢出时询问它。
标签: python game-engine blender