DotNaos / Orions-Destiny

Von Oliver, Timon, Dominik.
MIT License
0 stars 0 forks source link

Already existing component #4

Closed DotNaos closed 1 year ago

DotNaos commented 1 year ago

Programm stürzt ab, wenn einem GameObjekt mehrmals die gleiche Komponente hinzugefügt wird.

DotNaos commented 1 year ago
// check if component already exists, if so, overwrite it
        for (int i = 0; i < components.size(); i++) {
            Component existingComponent = components.get(i);
            if (existingComponent.getClass().equals(c.getClass())) {
                components.set(i, c);
                c.gameObject = this;
                return;
            }
        }

Oder: 
// Ignorieren
for (Component component : components) {
            if (component.getClass() == c.getClass()) {
                System.out.println("Error: Component already exists");
                return;
            }
        }