Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

NetworkTransform not working on client

Discussion in 'Connected Games' started by TerabyteTim, Jun 20, 2015.

  1. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    100
    So I'm trying to sync movement between two programs using UNET. I have them connecting fine, and seeing eachother/registering the player controllers. When I move the network player on the host that has "Local Player Authority" checked and a NetworkTransform component, I see it move on both the host and the client. However when I move the second object on the client, which has "Local Player Authority" checked on the client but not the server, I don't see it move on the server. Is there something special I need to set up in order for NetworkTransform to broadcast data from the client to the server?
     
    ahungrybear likes this.
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    778
    If you want to send data from client to server, the object must be a player object.
    Prefabs in the NetworkManager will be player object automatically, other objects have to be added (on the server, not on the client) with NetworkManager.AddPlayerForConnection(playerConnection, yourGameObject, aNewControllerID);
     
  3. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    100
    Yeah, I have my network player in the NetworkManager's "Player Prefab" field
     
  4. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    100
    My NetworkPlayer prefab has a NetworkIdentity script, a NetworkTransform script, and a NetworkBehaviour script.
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    778
    That should be right. But LocalPlayerAuthority should be the same on server and client, not just client alone.
    If you deactivate it on the server, I think the server ignores incoming messages (since you declared that it shouldn't get LocalPlayerAuthority)
    The checkbox just says "this object can be controlled by the owner".
     
  6. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    100
    Weird, if you only set some of them to "Local Player Authority" it doesn't work, but if you set every instance of a player object in the scene to that it works. It's functioning now, thanks a ton!
     
  7. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    I'm having this same issue. Client transform is being synchronized on the Server/Host, but Server/Host transform isn't being updated on the Client. I have "Local Player Authority" checked and the objects have a NetworkIdentity and a NetworkTransform. They have a script for input/movement using velocity (the objects have rigidbodies), and the NetworkTransform component has "Sync Rigidbody 3D" selected.

    EDIT - I also tried enabling "Multiple Client Mode", but it disables itself when entering play mode.
     
    Last edited: Jun 30, 2015
    rajeev-c and christophermrau like this.
  8. brickbrick

    brickbrick

    Joined:
    Aug 31, 2015
    Posts:
    1
    I'm having the same problem re. "Multiple Client Mode" disabling itself whenever I enter play mode or build my project. If I build my project and then run it simultaneously in Unity, I am unable to connect as a client in one game player while the other is hosting, unless I type in an address besides localhost (which is the hosting address) i.e. it seems like it won't let me have more than one client (the only client it is allowing is the host). I feel as though enabling Multiple Client Mode should fix this, but I can't enable it!!
     
  9. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    I ended up solving (I guess you could call it that) the issue by rebuilding the player prefab from scratch. I made sure to attach the NetworkTransform component last, and it's working fine now.
     
  10. desertkun

    desertkun

    Joined:
    Jan 13, 2016
    Posts:
    8
    Sorry for old thread, but in case anyone still wonders how to enable checkbox "Multiple Client Mode":

    Code (CSharp):
    1. Utility.useRandomSourceID = true;
    Yep, GUI lies, I've searched thought sources and found this:
    Code (CSharp):
    1. Utility.useRandomSourceID = EditorGUILayout.Toggle("Multiple Client Mode:", Utility.useRandomSourceID);
     
  11. rajeev-c

    rajeev-c

    Joined:
    Aug 4, 2015
    Posts:
    2
    I was getting same issue and it got solved when I have attached the NetworkTransform component last.
     
  12. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,004
    That sounds like the problem is due to Order of execution. You are probably executing movement code on remote objects and when you added it last it just so happend to have a different order. Just my speculation.
     
    rajeev-c likes this.
  13. jfa257

    jfa257

    Joined:
    Jul 17, 2013
    Posts:
    3
    sun_stealer likes this.
  14. sun_stealer

    sun_stealer

    Joined:
    Oct 4, 2016
    Posts:
    24
    @jfa257 I also read this in the documentation, and it's extremely confusing. What's the difference between a NetworkTransform object that exists in the scene from the beginning, and the spawned one? Why the former won't synchronize?
     
  15. jfa257

    jfa257

    Joined:
    Jul 17, 2013
    Posts:
    3
    well, basically I presume the spawned one has a reference both ways, server/client and client/server. I tested it and the server can send network updates to the client (tested with a network transform prefab that was not spawned), but since the object its not in the list of spawned objects, when the client tries to send an update, its not possible, to the point of classes not running methods because the transform parameters are not allowed to be updated.
     
  16. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    352
    Important, for 2018 we determined that

    There is some flakiness with NetworkTransform if you are using localhost during development, perhaps particularly on Mac.

    if you have a NetworkTransform with local authority system, it often erratically WILL NOT WORK when you are testing it in a localhost setting.

    (Further, this might sound bizarre but I found that - say you have a few PCs/Macs on your desktop, once you "do" do it over a LAN, the project will in fact then work (sometimes?) via localhost, which seems unbelievable but seemed to happen!)

    In short, if you are experiencing this incredibly annoying problem, it's really worth getting the project on a few actual machines on LAN, get away from localhost testing. S***ty issue.
     
  17. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    352