Skip to content

Unable to Send Message while Unity is not Instantiated #500

Answered by Naton-1
Naton-1 asked this question in Help Wanted!
Discussion options

You must be logged in to vote

Solution

This has been resolved. The problem is that the window Event Listener's function was using old state. That's why it said that Unity wasn't instantiated. I moved the openWarningDialog function inside the useEffect() containing the window Event Listener, and added isLoaded in the dependency array.

Correct Code

import React, { useEffect, useState, useCallback, useRef } from 'react';
import { Button, timeoutsShape } from 'reactstrap';
import { Unity, useUnityContext } from "react-unity-webgl";

function CardGame(props) {
    const UNITY_userIsPlayingGame = useRef(0);
    const UNITY_sessionID = useRef();
    const UNITY_playerScore = useRef();

    const { unityProvider, requestFulls…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Naton-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant