Repository: 4ian/GDevelop
File: newIDE/app/src/EditorFunctions/index.js (JavaScript)

Code before:
              foundGroup.getName(),
              newGroupName,
              /* isObjectGroup=*/ true
            );
            foundGroup.setName(newGroupName);
            changes.push(
              `Renamed group "${groupName}" to "${newGroupName}" in scene "${scene_name}".`
            );
          }
          if (objects) {
            const newObjectNames = objects
              .map(object =>
                SafeExtractor.extractStringProperty(object, 'object_name')
              )
              .filter(Boolean);
            // Remove objects that are not in the list, and add new objects.
            const currentObjectNames = foundGroup
              .getAllObjectsNames()
              .toJSArray();
            currentObjectNames.forEach(objectName => {
              if (!newObjectNames.includes(objectName)) {
                foundGroup.removeObject(objectName);
              }
            });
            const globalObjects = project.getObjects();
            const sceneObjects = project.getLayout(scene_name).getObjects();
            newObjectNames.forEach(objectName => {
              if (!currentObjectNames.includes(objectName)) {
                if (
                  sceneObjects.hasObjectNamed(objectName) ||
                  globalObjects.hasObjectNamed(objectName)
                ) {
                  foundGroup.addObject(objectName);
                } else {
                  warnings.push(
                    `Object "${objectName}" not found in scene "${scene_name}", so it was not added to group "${groupName}".`
                  );
                }
              }
            });
            changes.push(
              `Modified objects of group "${groupName}" in scene "${scene_name}".`
            );
          }
        }
      });

      // Notify the editor that object groups have been modified
      onObjectGroupsModifiedOutsideEditor({
        scene,
      });

Review comment (suggestion):
You already have it?
```suggestion
            const sceneObjects = scene.getObjects();
```

I see any get as suspicious if I don't see a check before for existence.

Code after:
              foundGroup.getName(),
              newGroupName,
              /* isObjectGroup=*/ true
            );
            foundGroup.setName(newGroupName);
            changes.push(
              `Renamed group "${groupName}" to "${newGroupName}" in scene "${scene_name}".`
            );
          }
          if (objects) {
            const newObjectNames = objects
              .map(object =>
                SafeExtractor.extractStringProperty(object, 'object_name')
              )
              .filter(Boolean);
            // Remove objects that are not in the list, and add new objects.
            const currentObjectNames = foundGroup
              .getAllObjectsNames()
              .toJSArray();
            currentObjectNames.forEach(objectName => {
              if (!newObjectNames.includes(objectName)) {
                foundGroup.removeObject(objectName);
              }
            });
            const globalObjects = project.getObjects();
            const sceneObjects = scene.getObjects();
            newObjectNames.forEach(objectName => {
              if (!currentObjectNames.includes(objectName)) {
                if (
                  sceneObjects.hasObjectNamed(objectName) ||
                  globalObjects.hasObjectNamed(objectName)
                ) {
                  foundGroup.addObject(objectName);
                } else {
                  warnings.push(
                    `Object "${objectName}" not found in scene "${scene_name}", so it was not added to group "${groupName}".`
                  );
                }
              }
            });
            changes.push(
              `Modified objects of group "${groupName}" in scene "${scene_name}".`
            );
          }
        }
      });

      // Notify the editor that object groups have been modified
      onObjectGroupsModifiedOutsideEditor({
        scene,
      });