Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled parameter not included in awaiting component when create script #7361

Open
YuniChou opened this issue Feb 19, 2025 · 5 comments
Open
Assignees

Comments

@YuniChou
Copy link

Hi all, I'm having trouble synchronizing the enabled attribute of a script.
I will import the script files after calling app.scene.loadScene and it will miss the initializeComponentData function (script/system.js).
The script should bind automatically on entity when registerScript runs, as it checks is there any components awaiting for script. (script-registry.js:134).

However, I found that the enabled value from _scriptsData is missing in the create function’s parameters.
Would it be reasonable to add it back like the example below?

Image

Waiting for your feedback and suggestions. Thank you!

@marklundin
Copy link
Member

Hey @YuniChou thanks for flagging this. Do you have a repro of this error?

@YuniChou
Copy link
Author

YuniChou commented Feb 21, 2025

Hi @marklundin , here is my repo that can reproduce.
Thanks for taking a look at this!

I'm making a project which whould like to load diffrient editor scenes using engine-only way.
There are two way can repro (main.js). The script hidden need to be disabled on Root entity.

A:
This one is a litte bit tricky.
In order to prevent error expection in __game-scripts.js will stuck the thread when app.start, I force game-scripts load after app.loadScene. It can 100% repro the flow.

B:
I don't call app.scenes.loadScene after app.preload to ensure __game-scripts.js load first.
There is a chance that the flow may occur, because the script is not ready when initializeComponentData is called.

Following the other proper route indeed avoids the component awaiting situation,
but I'm troubled because the enabled parameter isn't working. 🙇‍♂️

@marklundin
Copy link
Member

Thanks for the repro @YuniChou 🙏

I'm not 100% clear on the issue. I can see you have an empty dummy__game-scripts.js but not clear why you're overriding the fields in the config.json.

I have stripped out that part so it just loads the config, and you can see that it correctly does not initialize hidden script which is disabled. You can check this preview here. Let me know if I'm missing something obvious here.

@YuniChou
Copy link
Author

YuniChou commented Feb 21, 2025

Sorry for making you misunderstand! Let me use another example to clarify.
preview here

Without overriding anything, I set hidden.js preload to false and will manually load it later.
The flow works on https://playcanv.as/b/1d3a4567;

The Box entity's hidden script enabled is set to true.
The Root entity's hidden script enabled is set to false.
After manually loading hidden.js, both Box and Root's hidden scripts will be triggered.

const asset = app.assets.find('hidden.js');
app.assets.load(asset);

Or is this something I shouldn't do? 🙏

config.json

{
    "215181886": {
      "name": "hidden.js",
      "preload": false,
    }
}

2175667.json

{
    "e951e842-82e0-11ee-9eae-baf4d5e490e2": {
      "name": "Root",
      "components": {
        "script": {
          "enabled": true,
          "order": ["hidden", "hello"],
          "scripts": {
            "hidden": { "enabled": false, "attributes": {} },
            "hello": { "enabled": true, "attributes": {} }
          }
        }
      },
    },
    "e952058e-82e0-11ee-9eae-baf4d5e490e2": {
      "name": "Box",
        "script": {
          "enabled": true,
          "order": ["hidden"],
          "scripts": { "hidden": { "enabled": true, "attributes": {} } }
        }
      },
}

@Maksims
Copy link
Collaborator

Maksims commented Feb 21, 2025

Without overriding anything, I set hidden.js preload to false and will manually load it later. The flow works on https://playcanv.as/b/1d3a4567;

The Box entity's hidden script enabled is set to true. The Root entity's hidden script enabled is set to false. After manually loading hidden.js, both Box and Root's hidden scripts will be triggered.

In sync or async loading scenarios, initialize method of scripts, should not trigger if any of:

  1. Entity or any of its ancestors are disabled.
  2. Script is disabled within Script Component.

So if this behaves differently, then it is bug indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants