Nullreference on NetworkRunner after an RPC

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.

Nullreference on NetworkRunner after an RPC

FergalM
2022-01-20 11:12:51

Hello !

I got this nullref after an RPC, it happens at the end of the method. But I can't access the NetworkRunner.cs code to check what went wrong.

Here is the RPC method :

The class of this method inherits indirectly from NetworkBehaviour.

Any idea of what I did wrong and how can I fix it ?

Comments

FergalM
2022-01-23 17:22:59

Hello, I'm back !

So for the NullReferenceException at Fusion.NetworkRunner.get_Stage () (at Fusion/Fusion.Runtime/Runner/NetworkRunner.cs/308), I found out what was the issue !

The problem was coming from the fact that I manually loaded new scenes once I was connected and the networked objects from those new scenes were not referenced by the runner.

To fix this, I created a custom INetworkSceneObjectProvider that I passed to the runner when calling the StartGame method. The important part that I missed was to add these lines of code :

Runner.InvokeSceneLoadStart();

  • when you start to a load new scenes,

Runner.InvokeSceneLoadDone();

  • when you finish loading new scenes,

and Runner.RegisterUniqueObjects(m_sceneNetworkedObjects.Values); right before Runner.InvokeSceneLoadDone();

  • .

And be sure that you have loaded all your scenes before trying to make an RPC from one of these new networked objects ! (I noticed a mistake in my architecture thanks to this haha)

Tobias
2022-01-24 16:30:13

Thanks for the update. Glad you found this.

I will check with the colleagues if this is something we would add to the docs.

Back to top