Closed zetachua closed 8 months ago
You need to deconstruct unityProvider
from the useUnityContext
hook, you're trying to deconstruct unityContext
instead - which is indeed not defined.
Either use
const unityContext = useUnityContext({
Or use
const { unityProvider } = useUnityContext({
Hey Jeffrey! I just tried that it works! thank you:)
Please avoid duplicates
Language and Compiler
Vanilla JavaScript
What environment are you using?
Local Development Server
When does your problem occur?
While writing code
What does your problem relate to?
The problem seems Module related
React-Unity-WebGL Version
9.5.0
React Version
18.2.0
Unity Version
2022.3.16f1
What happened?
I literally just pasted the getting started code and created a react project, my file structure is
react-unity-webgl --core --web ----public ------Build2 ----src ------app.jsx
its saying that unityContext is undefined... i have no idea what to do as ive looked thru all the forms and chatgpt...send help thanks
Reproducible test case
import './App.css' import { Unity, useUnityContext} from "react-unity-webgl";
function App() { const {unityContext} = useUnityContext({ loaderUrl: "/Build2/Build2.loader.js", dataUrl:"/Build2/Build2.data.unityweb", frameworkUrl:"/Build2/Build2.framework.js.unityweb", codeUrl: "/Build2/Build2.wasm.unityweb", }); console.log(unityContext,"meow") return
;
}
export default App;
Would you be interested in contributing a fix?