Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Call ClientRPC immediately after NetworkServer.Spawn

Discussion in 'Multiplayer' started by Curious-George, Jul 8, 2017.

  1. Curious-George

    Curious-George

    Joined:
    Nov 8, 2012
    Posts:
    130
    There has to be a way to do this.

    I have an object that needs to be initialized with runtime data immediately after being spawned on a client, but this doesn't seem to work. On the server side, I'm sending an RPC immediately after calling NetworkServer.Spawn, but somehow, collision handlers and update functions still manage to run on the client before the RPC makes it there.

    Note: This isn't a simple object with a single script attached to it. It's a complex object with a tangled web of interactions between itself and other scene objects/scripts, and needs to be initialized immediately after being spawned for everything to work properly.

    What's the fix for this?

    Thanks
     
  2. Curious-George

    Curious-George

    Joined:
    Nov 8, 2012
    Posts:
    130
  3. TheWesselGames

    TheWesselGames

    Joined:
    Aug 31, 2016
    Posts:
    31
    You could make a bool that you set to true in the cliënt rpc. As long as the bool isnt true return the update function on the cliënt.
     
  4. Curious-George

    Curious-George

    Joined:
    Nov 8, 2012
    Posts:
    130
    The problem with a solution like this is that it doesn't scale well. Every object that you wanted to spawn would have extra requirements in addition to being a prefab with a NetworkIdentity.

    In our case, we're spawning several different types of objects. Rather than integrating some hack into each one of them though, it's much easier to have all the game-logic specific initialization in one place, where the spawning happens. That also leaves us open to using those same prefabs in a non-networked implementation.

    In any case, I've worked around this problem at this point.

    Thanks