Search Unity

Resolved In-Scene Place Object got. An RPC called on a NetworkObject that is not in the spawned object list

Discussion in 'Netcode for GameObjects' started by deadmandrive, Dec 4, 2023.

  1. deadmandrive

    deadmandrive

    Joined:
    Feb 12, 2013
    Posts:
    7
    Hi.
    I have a GameObject call GameControllerManager which is not a prefab.
    GameControllerManager use NetworkBehavior and attached NetworkObject component.
    There are pause function that use on this Manager.
    Receive Player Event on Pause and then use serverRpc -> ClientRpc to pause all player Game.
    In first level everything work normally as expected.
    But when players completed the level and proceed the next level,
    When player try to pause the game I got this error.

    InvalidOperationException: An RPC called on a NetworkObject that is not in the spawned objects list. Please make sure the NetworkObject is spawned before calling RPCs.

    What my understand is when you use In-Scene Place Object. You do not need to make a prefab and add in DefaultNetworkpPrefabs List. Which I wonder what might be the cause of this.

    GameControllerManager GameObject are manually copy and paste. I tried remove and add NetworkObject in GameObject as well. In GameControllerManager have OnNetworkSpawn and prove that are running on both scene. (with Debug.log)


    Any Ideas what I might done wrong?
    Should I run despawn GameControllManager before changing scene?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,870
    A common issue in this scenario is that in-scene placed network objects only work in networked scenes. This is easy to overlook, for instance by not using NetworkSceneManager to load a scene after the host/server is started. In that case the loaded scene is effectively an offline scene with any in-scene placed network objects being dysfunctional.
     
  3. deadmandrive

    deadmandrive

    Joined:
    Feb 12, 2013
    Posts:
    7
    Hi. Thank you for your reply.
    I checked my code. I used NetworkSceneManager to Load the scene as follow.

    Code (CSharp):
    1.   nextLevelButton.onClick.AddListener(() =>
    2.   {
    3.       if (SceneManager.GetActiveScene().name == LoadingUI.Scene.MultiplayerScene01.ToString())
    4.       {
    5.           LoadingUI.LoadNetwork(LoadingUI.Scene.MultiplayerScene02);
    6.       }
    7.       else if (SceneManager.GetActiveScene().name == LoadingUI.Scene.MultiplayerScene02.ToString())
    8.       {
    9.           LoadingUI.LoadNetwork(LoadingUI.Scene.MultiplayerScene03);
    10.       }
    11.  
    12.   });
    Code (CSharp):
    1.   public static void LoadNetwork(Scene scene)
    2.   {
    3.       NetworkManager.Singleton.SceneManager.LoadScene(scene.ToString(), LoadSceneMode.Single);
    4.   }
    But it still not working.
     
    Last edited: Dec 6, 2023
  4. deadmandrive

    deadmandrive

    Joined:
    Feb 12, 2013
    Posts:
    7
    Is there anyone got this issue?
    Maybe NetCode bug?
    I hope to solve this soon but I will try to think for workaround.
     
  5. deadmandrive

    deadmandrive

    Joined:
    Feb 12, 2013
    Posts:
    7
    Got this solved now. Turn out it not GameControllerManager false.
    It is Player that Publish event to GameControllerManager.
    Which did not clear static data before move to other scene.