galacean / engine

A typescript interactive engine, support 2D, 3D, animation, physics, built on WebGL and glTF.
https://galacean.antgroup.com/
MIT License
4.04k stars 289 forks source link

Add `Script` in `onStart` may cause some functions to not be executed correctly. #2102

Closed cptbtptpbcptdtptp closed 1 month ago

cptbtptpbcptdtptp commented 1 month ago

link:https://github.com/galacean/editor/issues/2658 Case:

class Script1 extends Script {
      const engine = await WebGLEngine.create({ canvas: document.createElement("canvas") });
      const scene = engine.sceneManager.activeScene;
        onStart(): void {
          entity1.addComponent(Script2);
        }
      }
      class Script2 extends Script {
        onStart(): void {
            console.log('called');
        }
      }

      const entity = scene.createRootEntity("1");
      entity.addComponent(Script1);
      engine.run();