jeffreylanters / react-unity-webgl

React Unity WebGL provides a modern solution for embedding Unity WebGL builds in your React Application while providing advanced APIs for two way communication and interaction between Unity and React.
https://react-unity-webgl.dev
Apache License 2.0
1.73k stars 163 forks source link

Cannot read properties of undefined (reading 'dataUrl') #528

Closed determinationlove closed 11 months ago

determinationlove commented 11 months ago

Please avoid duplicates

Language and Compiler

Vanilla JavaScript

What environment are you using?

Local Development Server

When does your problem occur?

When the Unity Component mounts

What does your problem relate to?

The problem seems related to my project

React-Unity-WebGL Version

9.4.3

React Version

18.2.0

Unity Version

2022.3.6f1

What happened?

I put the entire folder "WebGL" created by Unity into the src folder in the React project.

Error:

use-unity-arguments.js:15 Uncaught TypeError: Cannot read properties of undefined (reading 'dataUrl')
at use-unity-arguments.js:15:55

It seems that all URLs are not set? However, console.log prints out unityProvider.unityProvider.unityConfig.dataUrl normally.

2023-10-22 00-48-02 2023-10-22 00-48-58

Reproducible test case

import { useEffect, useState } from "react";
import { Unity, useUnityContext } from "react-unity-webgl";

export default function CBT() {
    const unityProvider = useUnityContext({
        loaderUrl: "/WebGL/Build/WebGL.loader.js", 
        dataUrl: "/WebGL/Build/WebGL.data",
        frameworkUrl: "/WebGL/Build/WebGL.framework.js",
        codeUrl: "/WebGL/Build/WebGL.wasm",
    });

    useEffect(() => {
        console.log(unityProvider.unityProvider.unityConfig.dataUrl);
        // Print out: /WebGL/Build/WebGL.data
    }, []);

    return (
        <>
            <Unity
                unityProvider={unityProvider}
                style={{ width: 800, height: 600 }}
            />
        </>
    );
}

Would you be interested in contributing a fix?

determinationlove commented 11 months ago

I was so tired that I made a mistake and it has been fixed.