Description
Please avoid duplicates
- I checked all open issues and discussions and none of them matched my problem.
Language and Compiler
Babel and WebPack JavaScript
What environment are you using?
Server Side Renderering
When does your problem occur?
When the Unity App is running
What does your problem relate to?
I don't know
React-Unity-WebGL Version
9.4.0
React Version
18.2.0
Unity Version
2022.2.9f1
What happened?
Hello!
We are trying to add build versions (debug, release) of our player to our NextJS app. Essentially, we want to be able to toggle between builds on a staging or even production environment for debugging purposes, but without reloading the page if possible.
We have put our versions in the public folder like stated and both versions are able to load when the URLs are hardcoded in the useUnityContext params.
Though, it seems that we are unable to dynamically change the values after the player has loaded.
Here's a simplified example of what we're trying to achieve (just a proof of concept for now)
const [isDebugMode, setIsDebugMode] = useState(false);
const playerVersion = isDebugMode ? 'debug' : 'release';
const playerCompression = isDebugMode ? '' : '.br';
const {
unityProvider,
} = useUnityContext({
loaderUrl: `/player/${playerVersion}/Build/${playerVersion}.loader.js`,
dataUrl: `/player/${playerVersion}/Build/${playerVersion}.data${playerCompression}`,
frameworkUrl: `/player/${playerVersion}/Build/${playerVersion}.framework.js${playerCompression}`,
codeUrl: `/player/${playerVersion}/Build/${playerVersion}.wasm${playerCompression}`,
streamingAssetsUrl: `/player/${playerVersion}/StreamingAssets`,
});
// ...
return (
<div>
<button onClick={() => setIsDebugMode(!isDebugMode)}>TOGGLE</button>
<div className={styles.unityContainer}>
<Unity
unityProvider={unityProvider}
/>
<UnityLoading
isLoading={!isReadyToStart}
value={loadingPercentage}
/>
</div>
</div>
);
We can see that the values changes, but nothing in the unityProvider.unityConfig
prop changes
Is this expected? Is there a way to toggle between players without reloading the page?
Thanks!
Reproducible test case
No response
Would you be interested in contributing a fix?
- yes, I would like to contribute a fix