Search Unity

Unity Multiplayer [SOLVED] How to allocate netID? And how to find object using netID?

Discussion in 'Multiplayer' started by Artaani, Nov 5, 2015.

  1. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    419
    New multiplayer in 5.1 is just amazing! But...


    Where is analog of Netwok.AllocateViewID and NetworkView.Find?


    I very hope Unity developers didn't remove the ability to allocate and set an ID manualy. It is very important feature for spawn a complex objects with many NetworkIdentity components inside.
    Simply say, I need a custom spawn function similar as here.
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  3. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    419
    Thanks for quick response.

    I've noticed this Custom spawn function in the manual. But to be honest, I not really understand why it needed. It doesn't looks like something similar to this.


    I asked it because I need to spawn a prefab which have NetworkIdentity on the root. But also have several NetworkIdentity components on its childs. I tried next things:

    1. When I perform NetworkServer.Spawn only for root - only NetworkIdentity on the root have new netID (not 0)
    2. When I perform NetworkServer.Spawn for each NetworkIdentity in the prefab - every child turned out unparented from its parent.


    In previous network system I handled with it by allocation several new NetworkViewID for each child and assign it manually via RPC. But I am not sure what I can do now.
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    NetworkIdentity components must be on the root game object of the prefab. Having them within the heirarchy of a prefab is not supported by the spawning system.
     
  5. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    419
    And there is no any native function to allocate new netID in order to assign it manually?
    Such as Netwok.AllocateViewID?
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    The new system is not the old system. In the old system, authority was very distributed, which was very flexible but it allowed developers to build architectures that were difficult to understand, debug, and make secure.

    The new system consolidates distributed authority in the server/host and consolidates local authority in the player. This is less flexible, but provides a model that is easy to make secure, and more difficult to build spaghetti architectures that are hard to debug and visualize.

    NetworkInstanceIds are allocated by the server only.

    Network identity on child objects within prefabs is something that comes up frequently as it was a common implementation pattern with the old system, but it is just not the way the new system works.

    In UNet, players do things. Players send Commands. Players have an implicit secure identity associated with their connection on the server that other players & clients cannot spoof or impersonate. Input from clients goes through the player object on the server. This has been watered down a little with AssignClientAuthority, but the server-side authority model stands.

    So instead of a child object like a gun firing, the player fires. Maybe the gun still "fires" locally, but the networked event for firing a gun is done by the player, NOT the gun.

    What if the player is dead? the gun does not know.. But the player knows, and can intercept that network request from a (cheating) client and not fire the gun.

    So:

    And the "gun" slot would be populated by dragging the gun child game-object into the slot on the root object of the player.
     
    MikeBaldwin, schkorpio, atto and 2 others like this.
  7. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    419
    Aha! I see.
    Seems like I need to redefine my vision of multilayer architecture. It is hard, but important. : )

    So, if I understand right. Every object should have only one NetworkIdentity on the root. And if I want to do something on the child - I need to do it via "controller" on the root.

    And my previous architecture, when objects have many NetworkView components inside - is wrong. Okay, at least now I am sure in it.

    Thanks for detailed answer. : )
     
    rikey likes this.
unityunity