Search Unity

(Solved)SpawnWithClientAuthority doesn't assign LocalPlayerAuthority

Discussion in 'Scripting' started by tijanikun, Feb 11, 2019.

  1. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    Hello,
    I have a problem when i want to spawn the player gameobject trought a custom prefab with localplayerauthority that allow to choose the character, but when the 2nd object spawn, it doesn't have the authority

    Im using that:
    Code (CSharp):
    1.  
    2.     [Command]
    3.     public void CmdSpawn()
    4.     {
    5.         GameObject go = (GameObject)Instantiate(playerselected, SpawnPoint2.transform.position, Quaternion.identity);
    6.         NetworkServer.SpawnWithClientAuthority(go, connectionToClient;
    7.     }
    Im sure it doesn't have localplayer... because this script is destroyed on the player
    Code (CSharp):
    1. if (!isLocalPlayer)
    2.         {
    3.  
    4.             AudioListenerCamera.SetActive(false);
    5.             Camera2.enabled = false;
    6.             Destroy(this);
    7.             return;
    8.         }
    Can you help me please?
     
  2. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    Still stuck, note that both prefabs have network identity with localplayer set on inspector
     
  3. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    Please?
     
  4. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    I beg you x.x
     
  5. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    tijan, can you share a little bit more of your code please. With the example code we don't know you're using
    Destroy(this);
    on the server, instead of the local client.
     
  6. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    My script got more than 1500 line, destroy(this) destroy the script of player who aren't suppose to be controlled on client side, it works well at this moment

    Here the codes:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.Events;
    4. using UnityEngine;
    5. using UnityEngine.Networking;
    6. using UnityEngine.UI;
    7.  
    8. public class PlayerController_Net : NetworkBehaviour
    9. {
    10.     public bool canWallJump = true;
    11.     public int currentHealth;
    12.     public Texture viseurTexture;
    13.     public Texture healthTexture;
    14.     public float hpbarlenght;
    15.     public Texture fondTexturebar;
    16.     public Texture ammoBarTexture;
    17.     public float ammobarlenght;
    18.     public float ammobarpercent;
    19.     public Texture manaBarTexture;
    20.     public float manabarlenght;
    21.     public float manabarpercent;
    22.     public GameObject ToPManager;
    23.     public bool GradinCantAttack = false;
    24.     public float timeTeam = 15;
    25.     public bool beforeRoundTeam = true;
    26.     [SyncVar] public bool DontAttack = false;
    27.     public enum Selection { none, minato, saitama, goku, war };
    28.     public Selection currentSelect;
    29.     //  public GameObject MinatoButton;
    30.     // public bool minato;
    31.     public GameObject playerselected;
    32.     public GameObject MinatoPlayer;
    33.     //   public GameObject SaitamaButton;
    34.     // public bool Saitama;
    35.     public GameObject SaitamaPlayer;
    36.     //   public GameObject GokuButton;
    37.     //  public bool Goku;
    38.     public GameObject GokuPlayer;
    39.     //    public GameObject WarButton;
    40.     // public bool War;
    41.     public GameObject WarPlayer;
    42.     public GameObject LobbyFrom;
    43.     public bool airDodgeFall;
    44.     public int team;
    45.     bool heavyStuckColliderBool = false;
    46.     bool runDodgeBool = false;
    47.     bool chargeStuck = false;
    48.     bool dodgeJumpGroundBool = false;
    49.     bool dodgeJumpCancelCorou = false;
    50.     bool dodgeJumpCanceled = false;
    51.     bool dodgeJumpCancel = false;
    52.     bool heavyWaitBool = false;
    53.     bool WarHeavyStun = false;
    54.     bool canHeavy = true;
    55.     bool HeavyStuckBool = false;
    56.     bool canFoot = false;
    57.     bool afterHoldHeavy = false;
    58.     float startTime = 0f;
    59.     float holdTime = 0.3f;
    60.     public AudioSource Slash;
    61.     public Image imageCooldownAbility1;
    62.     public Image imageCooldownAbility2;
    63.     public Image imageCooldownAbility3;
    64.     public Image imageCooldownAbility4;
    65.     public Image imageCooldownAbility5;
    66.     bool isCoolDown1;
    67.     bool isCoolDown2;
    68.     bool isCoolDown3;
    69.     bool isCoolDown4;
    70.     bool isCoolDown5;
    71.     public bool canGreyFire = true;
    72.     public bool canGaruru = true;
    73.     public bool canGaia = true;
    74.     float SpPerSecond = 3f;
    75.     private float regenSp;
    76.     float ammoPerSecond = 5f;
    77.     private float regenAmmo;
    78.     public RectTransform ammobar;
    79.     [SyncVar(hook = "OnChangeAmmo")] public int currentAmmo = maxAmmo;
    80.     public const int maxAmmo = 100;
    81.     public RectTransform spbar;
    82.     [SyncVar(hook = "OnChangeSp")] public int currentSp = maxSp;
    83.     public const int maxSp = 100;
    84.     bool one_z = false;
    85.     bool timer_running;
    86.     float timer_for_double_z;
    87.     float delay = 0.5f;
    88.     float BraveSpeed = 50;
    89.     float moveSpeed = 8;
    90.     float jumpForce = 20;
    91.     float dodgeSpeed = 20;
    92.     float fallForce = -10;
    93.     public CharacterController controller;
    94.     float gravityScale = 7;
    95.     public Animator anim;
    96.     public Transform pivot;
    97.     float rotateSpeed = 30;
    98.     float runSpeed = 15;
    99.     float attackSpeed = 10;
    100.     float omegaSpeed = 50;
    101.     float clawSpeed = 30;
    102.     float clawSpeed2 = 180;
    103.     float wallSpeed = 30;
    104.     public GameObject Camera1;
    105.     public GameObject OmeCamera;
    106.     public Camera Camera2;
    107.     public Camera OmeCamera2;
    108.     public Camera cam;
    109.     public int CamMode;
    110.     public AudioSource DramonKillerSound;
    111.     public AudioSource SwordSound;
    112.     Rigidbody  Rigid;
    113.     bool action = false;
    114.     float cooldowntime = 50;
    115.     float cooldowntime2 = 40;
    116.     float cooldowntime3 = 20;
    117.     float cooldowntime4 = 15;
    118.     float cooldowntime5 = 1;
    119.     float cooldowntime6 = 1;
    120.     float cooldowntime7 = 0.3f;
    121.     float cooldowntime9 = 5;
    122.     float cooldowntime10 = 40;
    123.     float cooldowntime12 = 0.5f;
    124.     float cooldowntime13 = 1f;
    125.     float cooldowntime14 = 2f;
    126.     float nextFireTime = 0;
    127.     float nextFireTime2 = 0;
    128.     float nextFireTime3 = 0;
    129.     float nextFireTime4 = 0;
    130.     float nextFireTime5 = 0;
    131.     float nextFireTime6 = 0;
    132.     float nextFireTime7 = 0;
    133.     float nextFireTime8 = 0;
    134.     float nextFireTime9 = 0;
    135.     float nextFireTime10 = 0;
    136.     float nextFireTime12 = 0;
    137.     float nextFireTime13 = 0;
    138.     float nextFireTime14 = 0;
    139.     bool charge;
    140.     bool Shot;
    141.     public AudioSource Impact2;
    142.     public Transform target;
    143.     public bool canAttack = true;
    144.     bool turning = false;
    145.     bool pushed = false;
    146.     bool WallHited = false;
    147.     bool Down1 = false;
    148.     bool Down2 = false;
    149.     bool downWallFall = false;
    150.     bool DownWall = false;
    151.     bool Down3 = false;
    152.     bool DashedUltra = false;
    153.     public bool canDodge = false;
    154.     private float knockBackCounter;
    155.     public GameObject AudioListenerCamera;
    156.     private Vector3 moveDirection;
    157.     public GameObject playerModel;
    158.     public Transform cameraTransform;
    159.     public Transform cameraTransform2;
    160.  
    161.     void Start()
    162.     { if (!isLocalPlayer)
    163.         {
    164.             AudioListenerCamera.SetActive(false);
    165.             Camera2.enabled = false;
    166.             OmeCamera2.enabled = false;
    167.             Destroy(this);
    168.  
    169.             return;
    170.         }
    171.         controller = GetComponent<CharacterController>();
    172.         ToPManager = GameObject.FindWithTag("ToPManager");
    173.     }
    174.  
    There's way more after

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.Networking;
    7. using UnityEngine.Networking.Match;
    8.  
    9. public class MyLobby : NetworkManager {
    10.     public bool canDontAttackLaunch = false;
    11.     public float TimeButtonJoin = 0f;
    12.     public bool endBeforeTime = false;
    13.     public bool newRound = false;
    14.     public bool DontAttackManager = true;
    15.     public bool DontStartRound = true;
    16.     public bool StartRoundBool = true;
    17.     public GameObject ToPManager;
    18.     public GameObject WarpToGame;
    19.     public float timeEndRound = 300f;
    20.     public bool EndRoundBool = false;
    21.     public float timeStartRound = 15f;
    22.     public float timeStartRoundAttack = 15f;
    23.     public bool StartAttackBool = false;
    24.     public GameObject SpawnEnter;
    25.     public GameObject LobbyOption;
    26.     public GameObject TitleScreen;
    27.     private bool TitleBool;
    28.     public enum Selection { none, minato, saitama, goku, war };
    29.     public Selection currentSelect;
    30.     private float nextRefreshTime = 2f;
    31.     //  public GameObject MinatoButton;
    32.     // public bool minato;
    33.     public GameObject playerselected;
    34.     public GameObject MinatoPlayer;
    35. //   public GameObject SaitamaButton;
    36.    // public bool Saitama;
    37.     public GameObject SaitamaPlayer;
    38. //   public GameObject GokuButton;
    39.   //  public bool Goku;
    40.     public GameObject GokuPlayer;
    41. //    public GameObject WarButton;
    42.    // public bool War;
    43.     public GameObject WarPlayer;
    44.  
    45.  
    46.     public GameObject Player;
    47.     public void Start()
    48.     {
    49.  
    50.         RefreshMatches();
    51.     }
    52.     public void StartHosting()
    53.     {
    54.      
    55.         StartMatchMaker();
    56.         matchMaker.CreateMatch("Room" + TimeButtonJoin, 4, true, "", "", "", 0, 0, OnMatchCreated);
    57.         DontStartRound = false;
    58.         LobbyOption.SetActive(false);
    59.         canDontAttackLaunch = true;
    60.     }
    61.  
    62.     private void OnMatchCreated(bool success, string extendedInfo, MatchInfo responseData)
    63.     {
    64.         base.StartHost(responseData);
    65.  
    66.         RefreshMatches();
    67.     }
    68.     public void Update()
    69.     {
    70.         TimeButtonJoin += Time.deltaTime;
    71.         ToPManager = GameObject.FindWithTag("ToPManager");
    72.  
    73.         WarpToGame = GameObject.FindWithTag("WarpToGame");
    74.         if (DontAttackManager == true && canDontAttackLaunch == true)
    75.         {
    76.             ToPManager.GetComponent<ToPManager>().CmdDontAttack();
    77.         }
    78.         if (EndRoundBool == false)
    79.         {
    80.             timeEndRound = 300;
    81.         }
    82.         else
    83.         {
    84.             timeEndRound -= Time.deltaTime;
    85.             ToPManager.GetComponent<ToPManager>().Timer3();
    86.         }
    87.         if (StartAttackBool == false)
    88.         {
    89.             timeStartRoundAttack = 15;
    90.         }
    91.         else
    92.         {
    93.             timeStartRoundAttack -= Time.deltaTime;
    94.             ToPManager.GetComponent<ToPManager>().Timer2();
    95.         }
    96.         if (DontStartRound == true)
    97.         {
    98.             timeStartRound = 15;
    99.         }
    100.         else
    101.         {
    102.             ToPManager.GetComponent<ToPManager>().Timer1();
    103.             ToPManager.GetComponent<ToPManager>().CmdTeamSelectMoment();
    104.             timeStartRound -= Time.deltaTime;
    105.         }
    106.  
    107.             if (timeStartRound < 0 & StartRoundBool == true)
    108.         {
    109.             ToPManager.GetComponent<ToPManager>().CmdStartRound();
    110.             WarpToGame.GetComponent<WarpToGame>().canRejoin = true;
    111.             WarpToGame.GetComponent<WarpToGame>().canRejoinSurvivor1 = true;
    112.             WarpToGame.GetComponent<WarpToGame>().canRejoinSurvivor2 = true;
    113.             DontAttackManager = true;
    114.             DontStartRound = true;
    115.             StartRoundBool = false;
    116.             StartAttackBool = true;
    117.         }
    118.             if(timeStartRoundAttack < 0)
    119.         {
    120.             EndRoundBool = true;
    121.             DontAttackManager = false;
    122.             ToPManager.GetComponent<ToPManager>().CmdAttack();
    123.             StartAttackBool = false;
    124.  
    125.         }
    126.         if (timeEndRound < 0 || endBeforeTime == true)
    127.         {
    128.             EndRoundBool = false;
    129.             DontAttackManager = true;
    130.             newRound = true;
    131.             endBeforeTime = false;
    132.         }
    133.         if(newRound == true)
    134.         {
    135.             StartRoundBool = true;
    136.             WarpToGame.GetComponent<WarpToGame>().canRejoin = false;
    137.             ToPManager.GetComponent<ToPManager>().EndRound();
    138.             ToPManager.GetComponent<ToPManager>().CmdTeamWonTime();
    139.             StartCoroutine(NewRound(10f));
    140.             newRound = false;
    141.         }
    142.  
    143.         nextRefreshTime -= Time.deltaTime;
    144.  
    145.         if (nextRefreshTime <= 0)
    146.         {
    147.          
    148.             RefreshMatches();
    149.             nextRefreshTime = 2;
    150.         }
    151.      
    152.         if(currentSelect == Selection.war)
    153.         {
    154.             playerselected = WarPlayer;
    155.         }
    156.         if (currentSelect == Selection.minato)
    157.         {
    158.             playerselected = MinatoPlayer;
    159.         }
    160.         if (currentSelect == Selection.saitama)
    161.         {
    162.             playerselected = SaitamaPlayer;
    163.         }
    164.         if (currentSelect == Selection.goku)
    165.         {
    166.             playerselected = GokuPlayer;
    167.         }
    168.         // currentSelect = MinatoButton.GetComponent<CharacterSelectionScreen>().currentSelect;
    169.         //  Goku = GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected;
    170.         // Saitama = SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected;
    171.         // War = WarButton.GetComponent<CharacterSelectionScreen>().WarSelected;
    172.     }
    173.  
    174.     private void RefreshMatches()
    175.     {
    176.         if (matchMaker == null);
    177.         StartMatchMaker();
    178.  
    179.         matchMaker.ListMatches(0, 10, "", true, 0, 0, HandleListMatchesComplete);
    180.  
    181.     }
    182.  
    183.     public void JoinMatch(MatchInfoSnapshot match)
    184.     {
    185.         if (matchMaker == null)
    186.             StartMatchMaker();
    187.  
    188.         matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, HandleJoinedMatch);
    189.         LobbyOption.SetActive(false);
    190.         canDontAttackLaunch = true;
    191.     }
    192.  
    193.     private void HandleJoinedMatch(bool success, string extendedInfo, MatchInfo responseData)
    194.     {
    195.         StartClient(responseData);
    196.     }
    197.  
    198.     private void HandleListMatchesComplete(bool success, string extendedInfo, List<MatchInfoSnapshot> responseData)
    199.     {
    200.         AvaibleMatchesList.HandleNewMatchList(responseData);
    201.     }
    202.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    203.     {
    204.      //   TitleScreen.SetActive(false);
    205.      //  LobbyOption.SetActive(true);
    206.             GameObject player = (GameObject)Instantiate(playerPrefab, SpawnEnter.transform.position, Quaternion.identity);
    207.          
    208.             NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
    209.  
    210.     }
    211.     // if (team == 1)
    212.     //    { player.GetComponent<MinatoController_Net>().team = 1; }
    213.     //int team = TeamHandler.GetComponent<TeamHandler>().team;
    214.  
    215.  
    216.     public void Wargreymon()
    217.     {
    218.         //  LobbySelect.GetComponent<MyLobby>().currentSelect = war;
    219.         currentSelect = Selection.war; // changes currentSel to Up.
    220.  
    221.     }
    222.  
    223.     //  MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    224.     //    SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    225.     //   GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    226.     //   WarSelected = true;
    227.  
    228.     public void Minato()
    229.     {
    230.         currentSelect = Selection.minato; // changes currentSel to Up.
    231.                                           //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
    232.                                           //  SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    233.                                           //   GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    234.                                           //   MinatoSelected = true;
    235.     }
    236.     public void Goku()
    237.     {
    238.         currentSelect = Selection.goku; // changes currentSel to Up.
    239.                                         //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;      
    240.                                         //   MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    241.                                         //   SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    242.                                         //   GokuSelected = true;
    243.     }
    244.     public void Saitama()
    245.     {
    246.         currentSelect = Selection.saitama; // changes currentSel to Up.
    247.                                            //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
    248.                                            //  MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    249.                                            ////  GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    250.                                            //SaitamaSelected = true;
    251.     }
    252.         public void PlayerChoosed(NetworkIdentity player)
    253.         {
    254.  
    255.             var conn = player.connectionToClient;
    256.  
    257.             var newPlayer = Instantiate<GameObject>(playerselected);
    258.  
    259.        // LobbyOption.SetActive(false);
    260.             Destroy(player.gameObject);
    261.             NetworkServer.ReplacePlayerForConnection(conn, newPlayer, 0);
    262.         }
    263.  
    264.     public IEnumerator NewRound(float waitTime)
    265.     {
    266.         yield return new WaitForSeconds(waitTime);
    267.         DontStartRound = false;
    268.  
    269.     }
    270. }
    271.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class OriginalPlayerPrefab : NetworkBehaviour {
    7.     public enum Selection { none, minato, saitama, goku, war };
    8.     public Selection currentSelect;
    9.     public GameObject playerselected;
    10.     public GameObject MinatoPlayer;
    11.     public GameObject SaitamaPlayer;
    12.     public GameObject GokuPlayer;
    13.     public GameObject WarPlayer;
    14.     public GameObject SpawnPoint2;
    15.     // Use this for initialization
    16.     void Start ()
    17.     {
    18.         SpawnPoint2 = GameObject.FindWithTag("SpawnPoint2");
    19.  
    20.     }
    21.    
    22.     // Update is called once per frame
    23.     void Update () {
    24.  
    25.         if (currentSelect == Selection.war)
    26.         {
    27.             playerselected = WarPlayer;
    28.         }
    29.         if (currentSelect == Selection.minato)
    30.         {
    31.             playerselected = MinatoPlayer;
    32.         }
    33.         if (currentSelect == Selection.saitama)
    34.         {
    35.             playerselected = SaitamaPlayer;
    36.         }
    37.         if (currentSelect == Selection.goku)
    38.         {
    39.             playerselected = GokuPlayer;
    40.         }
    41.         if (Input.GetButtonDown("WarButton"))
    42.         {
    43.             Wargreymon();
    44.         }
    45.         if (Input.GetButtonDown("MinatoButton"))
    46.         {
    47.             Minato();
    48.         }
    49.         if (Input.GetButtonDown("SwitchCharacter"))
    50.         {
    51.             CmdSpawn();
    52.         }
    53.  
    54.     }
    55.     [Command]
    56.     public void CmdSpawn()
    57.     {
    58.         GameObject go = (GameObject)Instantiate(playerselected, SpawnPoint2.transform.position, Quaternion.identity);
    59.         NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
    60.     }
    61.     public void Wargreymon()
    62.     {
    63.         //  LobbySelect.GetComponent<MyLobby>().currentSelect = war;
    64.         currentSelect = Selection.war; // changes currentSel to Up.
    65.  
    66.     }
    67.  
    68.     //  MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    69.     //    SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    70.     //   GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    71.     //   WarSelected = true;
    72.  
    73.     public void Minato()
    74.     {
    75.         currentSelect = Selection.minato; // changes currentSel to Up.
    76.                                           //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
    77.                                           //  SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    78.                                           //   GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    79.                                           //   MinatoSelected = true;
    80.     }
    81.     public void Goku()
    82.     {
    83.         currentSelect = Selection.goku; // changes currentSel to Up.
    84.                                         //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;      
    85.                                         //   MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    86.                                         //   SaitamaButton.GetComponent<CharacterSelectionScreen>().SaitamaSelected = false;
    87.                                         //   GokuSelected = true;
    88.     }
    89.     public void Saitama()
    90.     {
    91.         currentSelect = Selection.saitama; // changes currentSel to Up.
    92.                                            //  WarButton.GetComponent<CharacterSelectionScreen>().WarSelected = false;
    93.                                            //  MinatoButton.GetComponent<CharacterSelectionScreen>().MinatoSelected = false;
    94.                                            ////  GokuButton.GetComponent<CharacterSelectionScreen>().GokuSelected = false;
    95.                                            //SaitamaSelected = true;
    96.     }
    97. }
    98.  
    You think the local authority is assigned but my code got a problem?
     
    Last edited: Feb 14, 2019
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Note that Unet was not designed with the flexibility of destroying NetworkBehaviour components at your whim in mind. You should expect issues syncing state for objects you are doing so.

    On your actual problem, you check for client authority with hasAuthority, not isLocalPlayer. isLocalPlayer is to check only if this object is this client's special Player GameObject.

    Lastly, Unet is deprecated, if you are not 90+% done with your project you should be converting your game to an alternative networking API right now instead of figuring out how to use Unet. Unet is announced to be removed from Unity in either 2019.2 or 2019.3 (originally 2019.1, but the devs have said they are pushing it back a bit, but still its removal is just months away).
     
  8. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    @Joe-Censored talking about that, what would you suggest? Wait till Unity's Google Multiplay is released? Or just go with a 3rd party like Photon?

    @tijanikun There's a few things I'm confused with here. Firstly to spawn things with local player authority, you'd probably already want a local player there. Plus, when you're hitting the Destroy() method, it's not sending a message for that to happen on the server and the other clients, it's just happening on the local client. But then again having a player would not cause creating an object with local player authority to fail. In fact you need a local player to be able to assign an object with local player authority. Does that make sense?
     
  9. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    OriginalPrefabs = 1st thing spawned and localplayer Object
    PlayerGameObject = 2nd thing spawned with Authority

    Hi, im using hasAuthority now and the server can spawn the PlayerGameObject with the Authority, but only if i uncheck the localplayerauthority of the PlayerGameObject prefab on inspector, in that case i got a console error :
    AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.
    UnityEngine.Networking.NetworkServer:SpawnWithClientAuthority(GameObject, NetworkConnection)
    If i keep check the localplayerautority the spawned PlayerGameObject appear but doesn't have hasAuthority

    Should i keep uncheck local and keep the error?
    Note that i can't spawn the player from client side, nothing happens, not even error message

    Hi,
    The local player is the OriginalPrefabs
    Destroy() was on my script from a video, im guessing it's works because with that, the other player can't use this script because it disappear on their side because they are not localplayer (this script include mouvement) but now im using hasAuthority and i got other problem said before

    Thank you to give me some of your time by the way

    edit: i just noticed that when a client join the matchmaking room i got this error:
    There is already a player at that playerControllerId for this connections.
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    Can that be an issue?
     
    Last edited: Feb 15, 2019
  10. tijanikun

    tijanikun

    Joined:
    Aug 10, 2017
    Posts:
    129
    I found on google out that you can't use if(!hasAuthority) on start method, so i made it on update and with some other adjustments, it works!

    I couldn't do it without your advise, thank you both, this forum has so nice people~
     
    Joe-Censored likes this.
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    TL;DR: I really have no confidence anymore in using any network library from anyone else. Write it yourself. Rant below
    ---
    Well so far with the project I'm currently working on, I started it using 3rd party uLink. I put that project on the back burner partly because uLink got abandoned by its developers. A couple years later I rewrote the project from the beginning around Unet. Things were going good, but I estimate I spent about 3 months total of my spare time dealing with issues that were hard to investigate because they were from the black box part of Unet who's source has not been made public. I have made a few threads on my issues at various times, and the Unity developer who wrote the Unet LLAPI has been as responsive and helpful as he can, but that doesn't mean that bugs in code I cannot view suddenly do not exist.

    My last "final straw" issue for example was a problem that over a month of off and on trying to track down I finally narrowed down to some problem with fragmented channels causing outbound messages to get stuck in the outbound queue for that connection, eventually filling and blocking all communication with that single client, with no means provided by Unity to either just flush the queue or even query its contents. If I was right I figured I could spend the next 2 weeks of my available dev time writing and testing my own fragmented message system, and recompile the HLAPI to use it (because I was sending fragmented messages using Commands, ClientRpc, etc). If I was wrong, since I couldn't be actually sure my assessment was correct, I'd be out 2 more weeks dealing with a problem which was caused by depending on code I could not modify or even inspect. And who knows the next time something like that would come up down the road yet again?

    So I estimated it would take me 2 months to just write my own network API on top of the socket class. I'd already spent more than that just trying to troubleshoot Unet as it was. So that's what I decided to do. And since I had 18 months or so invested in my project around Unet, I would build in many Unet HLAPI like features to make my conversion easier. A week after I started on that Unity announced they were deprecating Unet, which didn't surprise me. My 2 month estimate turned into 2 1/2, and another week to convert my project, but it has been going great ever since. When I hit a networking issue, now I not only can go to the code to see what is going on, but I know the thing inside and out. Probably the best decision I've ever made with this project.

    Funny thing is Unity has been working on a new network implementation for what, a year now? All they really have to show for it is a no frills unreliable UDP transport wrapper (unreliable as in they don't implement reliability on top of UDP even though most projects will need it for some data). In less than 3 months I was able to throw together a system with per channel optional reliability and weak encryption, automatic message fragmentation up to near max int bytes in size, object spawning/destroy, automatic distance based object updates (don't get updates as often or at all from objects far from the player), basic syncvars and rpcs, and more.

    Unity has done what? Implemented a connection oriented unreliable transport on connectionless UDP, and really no other functionality. Why is Unity taking so long with this stuff though, I thought they have a whole team working on this, but just working during lunch and at night I was able to get so much more together in so much less time? I'm not saying my code is perfect or anything, and I'm mid tier as a programmer at best, but what is going on with Unity's stuff? Are they just focused on their Google server offering they can charge money for even though google's cloud servers are really too expensive already for most games to use? I'm usually a Unity fan boy, but the longer their new networking API is taking to get even minimal features it is just getting embarrassing. And this is their 3rd networking implementation the engine will have in just a few years.

    So long story short, I'd stop trying to use someone else's network library. The Socket class is really not that hard to use, and you can build any higher level functionality you actually need on top of it that fits your project well. The time it takes you to write your own networking code is actually likely less time than you will spend troubleshooting your networking problems coming from someone else's network library.
     
    Last edited: Feb 15, 2019