[Duplicated] Getting an InvalidOperationException

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

[Duplicated] Getting an "InvalidOperationException: Behaviour not initialized: Object not set."...

Flaemnova
2022-06-17 14:14:07

Hello,

I am trying to sync a game launch event for a multiplayer game from a game session.

The following is my instance RPC, the networked variable and place I call it from:

    [Networked(OnChanged = nameof(OnStateChanged))]     
    public NetworkBool LaunchGame { get; set; }    

    ...    

    // if player count for a session is full, launch game    
    Debug.Log("Player count reached."); // this line is printed out in the console    
    RPC_LaunchGame(true); // any other Log statements aren't printed past this line    
                    
    ...    

    [Rpc(sources: RpcSources.All, targets: RpcTargets.All)]    
    public void RPC_LaunchGame(NetworkBool state) LaunchGame = state;     

    ...    

    private static void OnStateChanged(Changed<GameLauncher> changed)    
    {    
        if(changed.Behaviour) changed.Behaviour.startGame();    
    }    

I get the following Exception:

InvalidOperationException: Behaviour not initialized: Object not set.    
Fusion.NetworkBehaviourUtils.ThrowIfBehaviourNotInitialized (Fusion.NetworkBehaviour behaviour) (at <147a77adcf864b659935f862fe8f5e7b>:0)    

I'm not sure if i'm missing any necessary steps for using RPCs.

From using Log statements, I'm certain the the exception is thrown when the program reaches :

RPC_LaunchGame(true);    

Any advice for using RPCs would be appreciated

Comments

Back to top