Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Network "Scene Objects"

Discussion in 'Multiplayer' started by RemDust, Mar 7, 2017.

  1. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    Hi guys,
    I find it really hard to handle what Unity calls "Scene Objects" (https://docs.unity3d.com/Manual/UNetSceneObjects.html)

    There is a really few amount of information and threads and I really wonder how I can be the only one having a hard time using networking behavior (command, rpc and stuff) with non player objects !!!

    I'm not talking about objects spawned by the network manager here but really about objects already here in the scene.

    In my case, I have a custom lobby scene, and I just can't get my scene objects to send command/rpc, I always end up with some error like "no authorization" or stuff -_-

    This is SO FRUSTRATING because I really feel like what I'm trying to do should be a Simple Thing !
    Anyway, if any of you guys have an advice on how to manager scene objects, it would be greatly appreciated ;)
     
  2. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Objects that are "already there" cannot send commands or RPCs, but they can call methods on your objects that are networked and vice/versa.
     
  3. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    This is not what is stated by the documentation (see the link I posted before) "Once scene objects have been spawned by NetworkServer.SpawnObjects() then they behave like every other spawned objects. Updates will be sent, and ClientRPC calls can be made."
     
  4. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Ok, then you are talking about two different things. In your previous message you said:

    "I'm not talking about objects spawned by the network manager here but really about objects already here in the scene."

    So, those are objects that are NOT spawned by NetworkServer.SpawnObjects().


    ---edit---
    Maybe this will clarify:
    If the object doesn't have doesn't have a NetworkIdentity, it can't do anything directly with the network.
     
  5. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    "All objects in the scene with a NetworkIdentity component will be disabled when the scene is loaded; on both the client and the server. Then, when the scene is fully loaded, NetworkServer.SpawnObjects() is called to activate these networked scene objects. This will be done automatically by the NetworkManager when the server scene finishes loading - or can be called directly by user code. This causes the networked scene objects to be spawned in a special way - the existing instances are hooked up to the network instead of new instances being created."

    This is SO UNCLEAR. My understanding is : objects already presents in scenes (and with network identity, obviously) will NOT be spawned like usual registered prefab but will be "activated by NetworkServer.SpawnObjects and then linked to network and be considered as spawned".

    Isn't this what the doc states ?!
     
    stinkyp likes this.
  6. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    So they're in both scenes, active, authority allowed (checkbox checked) and granted (NetworkIdentity.AssignClientAuthority) but you can't send network traffic from them?
     
  7. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    I'm not sure that AssignClientAuthority is really on, that's my buddy who's working on it right now.
    We sure looked messed with that function, I think I remember that we were not able to call AssignClientAuthority as there is no player prefab already spawn in that scene (it's the lobby, where the game client is already connected but the "player object" doesn't exist yet)

    But does this player object must be there to assign client authority ?
     
  8. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Correct, you can't assign authority until the object is "spawned." So you have to wait to do it until your game scene loads.
     
  9. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    But, is really assignclientauthority relative to the "player prefab" ? not the client ?
    I mean, my client is connected, Do I really need to have the player object ?
    If yes, that's a bummer ^^

    It sounds pretty ugly to spawn my player object, disable every behavior and rendering just to "have it" !
     
  10. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Authority means that you have the definitive/canonical/model copy of an object. Your changes are the "real" changes. By default, the server is the model for your game and has authority over all objects. If you want to control something and have your changes appear on other clients, you must have authority over it.

    AssignClientAuthority is per object. Yes, you need a player object if you want to have control over anything on the server. Everything that you are trying to directly manipulate on your client is a player object.
     
  11. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
  12. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    Wow, Lucas it looks like a huge work here, don't even know if I can handle it ^^'
    I'm gonna take a deeper look after my morning coffee :D

    Angus, thanks for this explanation, I guess I have to spawn a "dummy player object" in my lobby then...