Search Unity

UNet [Command] not working with 2019.3.0f6?

Discussion in 'UNet' started by smoore2171, May 17, 2020.

  1. smoore2171

    smoore2171

    Joined:
    Jul 14, 2014
    Posts:
    9
    I've started a brand new project on 2019.3.0f6 and for some reason I cannot get Commands to fire with the HLAPI to save my life. I understand HLAPI was deprecated with Unity 2018, but that support should run for it for 2 years after that final release.

    The code is fairly straight forward:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using UnityEngine;
    5. using UnityEngine.Networking;
    6.  
    7. public class Player : NetworkBehaviour
    8. {
    9.  
    10.     // Start is called before the first frame update
    11.  
    12.     void Start()
    13.     {
    14.             // register client events, enable effects
    15.             if (isLocalPlayer)
    16.             {
    17.                 CmdRegisterPlayer();
    18.             }
    19.     }
    20.  
    21.     [Command]
    22.     public void CmdRegisterPlayer()
    23.     {
    24.         if (!isServer)
    25.             return;
    26.  
    27.         // Register with GameManager
    28.         GameManager.gManager.playerJoined(this);
    29.     }
    30. }
    31.  
    This script is on the root object of the prefab specified as the "Player Prefab" under spawn info on the NetworkManager object with autocreateplayer checked.

    The game successfully creates a server/client using the network manager HUD, but when the client spawns, the CmdRegisterPlayer() fires on the client when I expect it to fire on the server (can confirm by getting a breakpoint on the client binary). The player prefab is correctly created on each and the authority appears correct on both the client and server.

    I've tried this with the NetworkIdentity component on the root object of the player prefab having both "Local Player Authority" checked and unchecked. Same result with both.

    Any ideas why this is failing? I've tried running the Cmd from the Update with [ClientCallback] as well and the same behavior happens. It always fires the function on the client. There are no warnings or errors in the console and there is only one NetworkIdentity in the player prefab (on the root object)
     
  2. smoore2171

    smoore2171

    Joined:
    Jul 14, 2014
    Posts:
    9
    This randomly started working. I believe there were some bad [SyncVar] attributes in a completely unrelated file that was causing these to fail. I'm not sure why, but removing those made the above start working. I guess attribute build warnings can cause downstream attributes to fail.