Skip to content

Commit 4c7e28f

Browse files
Removed unsafe detatch and unload method from source
1 parent 42a05ff commit 4c7e28f

File tree

1 file changed

+0
-39
lines changed

1 file changed

+0
-39
lines changed

module/source/hooks/use-unity-context.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -155,44 +155,6 @@ const useUnityContext = (unityConfig: UnityConfig): UnityContextHook => {
155155
[unityInstance]
156156
);
157157

158-
/**
159-
* Detatches the Unity Instance from the React DOM, by doing so, the Unity
160-
* Instance can be unloaded from the memory while the Unity component can be
161-
* unmounted safely.
162-
*
163-
* Warning! This is a workaround for the fact that the Unity WebGL instances
164-
* which are build with Unity 2021.2 and newer cannot be unmounted before the
165-
* Unity Instance is unloaded.
166-
* @see https://github.com/jeffreylanters/react-unity-webgl/issues/22
167-
*/
168-
const UNSAFE__detachAndUnloadImmediate = useCallback(
169-
/**
170-
* @returns A promise that resolves when the UnityInstance has been unloaded.
171-
*/
172-
async (): Promise<void> => {
173-
if (
174-
unityInstance === null ||
175-
typeof unityInstance.Module.canvas === "undefined"
176-
) {
177-
// Guarding the Unity Instance.
178-
console.warn(errorMessages.genericNoUnityInstance);
179-
return Promise.reject();
180-
}
181-
// Re-attaches the canvas to the body element of the document. This way it
182-
// wont be removed from the DOM when the component is unmounted. Then the
183-
// canvas will be hidden while it is being unloaded.
184-
const canvas = unityInstance.Module.canvas as HTMLCanvasElement;
185-
document.body.appendChild(canvas);
186-
canvas.style.display = "none";
187-
// Unloads the Unity Instance.
188-
await unload();
189-
// Eventually the canvas will be removed from the DOM. This has to be done
190-
// manually since the canvas is no longer controlled by the React DOM.
191-
canvas.remove();
192-
},
193-
[unityInstance]
194-
);
195-
196158
// Effect invoked when the loading progression changes. When the loading
197159
// progression is equal to or more than 1, the Unity Instance is considered
198160
// loaded. This will update the isLoaded state.
@@ -214,7 +176,6 @@ const useUnityContext = (unityConfig: UnityConfig): UnityContextHook => {
214176
takeScreenshot,
215177
addEventListener: eventSystem.addEventListener,
216178
removeEventListener: eventSystem.removeEventListener,
217-
UNSAFE__detachAndUnloadImmediate,
218179
};
219180
};
220181

0 commit comments

Comments
 (0)