Skip to content

Commit a616424

Browse files
youle31panzergame
authored andcommitted
UPBGE: Forbid setParent to an object in an inactive layer
Previously object was able to be parented between active and inactive objects. But this was introducing big troubles when adding an inactive object with active object children. To solve this issue the inter layer parenting is disallowed. Only active objects can be parented to active objects and the same for inactive objects.
1 parent cf38701 commit a616424

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: source/gameengine/Ketsji/KX_GameObject.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,13 @@ void KX_GameObject::SetParent(KX_GameObject* obj, bool addToCompound, bool ghost
318318
obj->GetSGNode() && // object is not zombi
319319
GetSGNode()->GetSGParent() != obj->GetSGNode() && // not already parented to same object
320320
!GetSGNode()->IsAncessor(obj->GetSGNode()) && // no parenting loop
321-
this != obj) // not the object itself
321+
this != obj) // not the object itself
322322
{
323+
if (!(GetScene()->GetInactiveList()->SearchValue(obj) != GetScene()->GetObjectList()->SearchValue(this))) {
324+
std::cout << "Warning: Child and Parent are not in the same gameobjects list (active or inactive).\n" <<
325+
"This operation is forbidden." << std::endl;
326+
return;
327+
}
323328
// Make sure the objects have some scale
324329
MT_Vector3 scale1 = NodeGetWorldScaling();
325330
MT_Vector3 scale2 = obj->NodeGetWorldScaling();
@@ -3530,6 +3535,7 @@ PyObject *KX_GameObject::PySetParent(PyObject *args)
35303535
}
35313536
if (!ConvertPythonToGameObject(logicmgr, pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
35323537
return NULL;
3538+
35333539
if (obj)
35343540
SetParent(obj, addToCompound, ghost);
35353541
Py_RETURN_NONE;

0 commit comments

Comments
 (0)