NullReferenceException: Object reference not set to an instance of an object

Options
Hello, I have been having this issue for quite awhile now and I have no clue why it is happening at this point.

The error is thrown when the code tries to execute the RPC call for "RPC_LoadedGameScene" in this function:

private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode) { currentScene = scene.name; if(currentScene == MultiplayerSettings.settings.matchScene) { isGameLoaded = true; photonView.RPC("RPC_LoadedGameScene", RpcTarget.MasterClient); } }

I have tried commenting out every line of code inside RPC_LoadedGameScene to see if it was failing inside, but it wasn't. I have also tried clearing and refreshing my RPC list, but it also didn't change anything. I have also tried calling a different RPC function to see if the problem was with that specific function, but it still threw the same error as the title. "photonView" is the provided PhotonView variable as this OnSceneFinishedLoading function is within a "MonoBehaviorPunCallbacks, IInRoomCallbacks" class. From my tests, it appears the problem is with photonView.RPC(), but I don't know why as it worked previously just fine. All that I changed is which scene this script is called from. After I switched scenes is when it started happening.

Any help would be much appreciated.

Comments

  • Hatchet
    Options
    Here's a better formatted version of the function

    private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
    {
    currentScene = scene.name;

    if(currentScene == MultiplayerSettings.settings.matchScene)
    {
    isGameLoaded = true;
    photonView.RPC("RPC_LoadedGameScene", RpcTarget.MasterClient);
    }
    }