NetworkObject of my NetworkBehaviour is null for object in scene

Options

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

Answers

  • Isaac_Augusto
    Options

    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
    Options

    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
    Options

    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