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! Your search result can be found below. Plus, we offer support via 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.

NetworkObject of my NetworkBehaviour is null for object in scene

andreparodi
2022-07-05 22:15:27

Hi,

I have a GameObject in my scene with a NetworkBehaviour which has an RPC. I have added a NetworkObject, saved the scene and can see the baked data which looks correct.

After awaiting runner.StartGame I try to invoke an RPC on this NetworkBehaviour but I get InvalidOperationException: Behaviour not initialized: Object not set.

I have added some traces which show that client is connected to the session properly. Is there something obvious i'm missing? Why would the Object property of a NetworkBehaviour be null? I can see the component in Unity and it has data in it. (I saw another similar question and the response was that the client was not connected but i'm sure this is not my case)

My debug info

Runner Info: [SessionInfo: IsValid=True, Name=Room_Player_130, IsOpen=True, IsVisible=True, Region=eu, PlayerCount=0, MaxPlayers=0, Properties=]

PlayerId: 1

myBehaviour.Object == null? True

Thanks

Andre

Comments

Isaac_Augusto
2022-07-13 10:26:24

Hi Andre,

"After awaiting runner.StartGame I try to invoke an RPC on this NetworkBehaviour"

How are you waiting before invoking the RPC? awaiting the StartGame() in a async or a Coroutine?

If you try to invoke the RPC on the Spawned() of the NetworkBehaviour this error still occurs?


Isaac Augusto

Photon Fusion Team

andreparodi
2022-07-14 15:05:35

Hi Isaac,

I solved my previous problem my Spawning the NetworkBehaviour instead of having it statically in the scene.

Now I have hit the problem again. The situation is:

I connect, join a room in client/server (just one client for now) and load a scene (on my own, not through the scene manager of fusion.

In this scene I have a NetworkBehaviour with an RPC defined (source All, target StateAuthority). When I try to invoke it I get the error reported above. Not that by the time I try to call this RPC I have already successfully called RPC on object that I have dynamically spawned using Spawn. So it's something i'm not doing properly when the networkbehaviour is statically in the scene.

Thanks

Andre

Isaac_Augusto
2022-07-14 15:28:30

Hi Andre,

You can load scenes on your own, but you need to provide Fusion with the requested NetworkObjects loaded on this new scene.

I would advice you to take a look at the scene loading entry: https://doc.photonengine.com/en-us/fusion/current/manual/scene-loading and the scene loading sample: https://doc.photonengine.com/en-us/fusion/current/samples/technical-samples/fusion-scene-loading.

Those will help you to understand and create your own custom scene loading system that will work correctly with Fusion. (Your problem is that the NetworkObject on the scene you loaded is not added to the simulation, thus, will not be able to call RPCs or even receive/send the state)

Hope that this helps.


Isaac Augusto

Photon Fusion Team

Back to top