Skip to content

Commit ad0073c

Browse files
committed
Avoid unnecessary changes when add child
1 parent 1d776d6 commit ad0073c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

engine/core/Scene.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,20 @@ void Scene::addEntityChild(Entity parent, Entity child, bool changeTransform){
372372

373373
transformChild.needUpdate = true;
374374

375+
if (transformChild.parent == parent){
376+
return;
377+
}
378+
375379
if (parent == NULL_ENTITY){
376-
if (transformChild.parent != NULL_ENTITY){
377-
size_t newIndex = findBranchLastIndex(findOldestParent(child)) + 1;
378-
moveChildToIndex(child, newIndex, true);
380+
size_t newIndex = findBranchLastIndex(findOldestParent(child)) + 1;
381+
moveChildToIndex(child, newIndex, true);
379382

380-
Transform& transformChild = componentManager.getComponent<Transform>(child);
383+
Transform& transformChild = componentManager.getComponent<Transform>(child);
381384

382-
transformChild.parent = NULL_ENTITY;
383-
if (changeTransform){
384-
// set local position to be the same of world position
385-
transformChild.modelMatrix.decompose(transformChild.position, transformChild.scale, transformChild.rotation);
386-
}
385+
transformChild.parent = NULL_ENTITY;
386+
if (changeTransform){
387+
// set local position to be the same of world position
388+
transformChild.modelMatrix.decompose(transformChild.position, transformChild.scale, transformChild.rotation);
387389
}
388390
}else{
389391
Signature parentSignature = entityManager.getSignature(parent);

0 commit comments

Comments
 (0)