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

Unity Toolkit Workaround #14754

Merged
merged 4 commits into from
Feb 1, 2024
Merged

Unity Toolkit Workaround #14754

merged 4 commits into from
Feb 1, 2024

Conversation

MackeyK24
Copy link
Contributor

Workaround to temp disable the Unity Toolkit scripts loading from playground loadScriptAsync. But load from BABYLON.Tools.LoadScriptAsync while debugging the issue

Workaround to temp disable the Unity Toolkit scripts loading from
playground loadScriptAsync. But load from BABYLON.Tools.LoadScriptAsync while debugging the issue
@bjsplat
Copy link
Collaborator

bjsplat commented Jan 31, 2024

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 31, 2024

@RaananW
Copy link
Member

RaananW commented Jan 31, 2024

Instead of merging this, let's find out what is wrong with the loadScript function. Can you reproduce that so I can debug this with you?

@MackeyK24
Copy link
Contributor Author

MackeyK24 commented Jan 31, 2024

Yo @RaananW ...

I found two issues...
The first issue why it didnt quite work right using the _loadScriptAsync but it did work correctly using Tools.LoadScriptAsync is because we are missing text/javascript for the type on the dynamic script tag.
So i added the attribute like so:

    private async _loadScriptAsync(url: string): Promise<void> {
        return new Promise((resolve) => {
            const script = document.createElement("script");
            script.setAttribute("type", "text/javascript");
            script.setAttribute("src", url);
            script.onload = () => {
                resolve();
            };
            document.head.appendChild(script);
        });
    }

The second is that the Tools.LoasScriptAsync which is an async wrapper for the Tools.LoadScript does not pass the scriptID thru to the underlying Tools.LoadScript. So I fixed the Tools.LoadScriptAsync like so:

    public static LoadScriptAsync(scriptUrl: string, scriptId?: string): Promise<void> {
        return new Promise((resolve, reject) => {
            this.LoadScript(
                scriptUrl,
                () => {
                    resolve();
                },
                (message, exception) => {
                    reject(exception || new Error(message));
                },
                scriptId
            );
        });
    }

That should fix things :)

Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm good with the changes, once you fix the missing docs :-)

@MackeyK24
Copy link
Contributor Author

What missing docs ?
Are you talking some sort of doc for the commit or are you talking docs in general for the whole toolkit ?

@RaananW
Copy link
Member

RaananW commented Jan 31, 2024

Just check the files, the error is there. You are missing code doc of one variable

@MackeyK24
Copy link
Contributor Author

I see now, sorry... Fixed missing param doc

@RaananW RaananW merged commit 124f73f into BabylonJS:master Feb 1, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants