Search Unity

Network.Instantiate Question

Discussion in 'Multiplayer' started by imgodot, Jan 16, 2014.

  1. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    My multiplayer client is calling Network.Instantiate for a prefab, call it "ship", with a NetworkView on it.
    The "ship" is moving around the scene and all is well.

    If I want the SERVER to be able to track my "ships" and the "ships" from other players,
    is there a way for the server to "know" about the "ships" when they were instantiated from the client?

    Thanks very much.

    -- Paul
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Network.Instantiate is called on all connected instances, also the server.
     
  3. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    appels,

    Thanks for the response, but I'm still not sure what to do.

    I call GameObject GO = Network.Instantiate(...) when IsServer = FALSE.
    My client code then has access to GO and can do things that modify the local instance of the game object.

    If that is the case, how does my server code get access to the GameObject GO that was created?

    I'm sorry if I'm being dense. This network stuff is confusing to me.

    -- Paul;
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Can you explain a bit more why you need the server (who in this case isn't the owner of the object) to access the object ?
    Not sure what you mean by 'tracking'.
     
  5. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    212
    My thought was to have the server track where each ship is so, if a ship for player A is within a certain distance of a ship for player B, it would trigger "battle mode" and mayhem would ensue.

    I'm a real Unity and multiplayer noob, but the only solutions I can come up with are:

    A) Use Network.Instantiate on each client when they are spawning a ship and send SOMETHING to the server to give it a reference to the ship gameobject so it can be tracked. I just don't know if that can be done or what the "something" would be.

    B) Don't use Network.Instantiate at all. Send an RPC when a ship should spawn which would trigger local instantiations on each client and the server and then the server could have a local reference of each ship to track them. I know that I'll need to assign a NetworkView ID myself and send it along in the RPC, but it seems relatively easy.

    Your thoughts?

    -- Paul