0
votes

I am working on a multiplayer game using UNET. Every time i host a match by playing the game in the editor, every player that joins is considered as server and the game works as intended. If i host a match by using a built game (not using the Unity editor), every player that joins is considered a client and they all spawn in the same network spawn position and also, every time that my enemy spawner tries to instantiate an enemy prefab, i get an error message.

I really can't understand what's going on.

I have tried following other tutorials online but nothing helped. I'll list the code and the errores below.

//To check if a player is a client or a server, i wrote this code in the //player setup script:

"if (isServer)
  Debug.Log("server");
 else
 Debug.Log("Client");"

//this code is used in the player scirpt to get damaged when is hit by an //enemy bullet

private void OnTriggerEnter2D(Collider2D hitInfo)
    {
        if (hitInfo.tag == "Enemy" || hitInfo.tag == "EnemyBullet")
        {
            RpcTakeDamage(10, "hit by enemy");
        }
    }

[ClientRpc]
    public void RpcTakeDamage(int _amount, string _sourceID)
    {
        if (!isHit)
        {
            StartCoroutine("HurtColor");
            currentHealth -= _amount;

    Debug.Log(transform.name + " now has " + currentHealth + " health ");

            if (currentHealth <= 0)
            {
                Die(_sourceID);
            }
        }

    }

//The Die function so far just destroys the player game object

//these errors show up when i join the game hosted by the built game

"Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check."

"CRC Local Dump PlayerSetup : 0"

"Trying to send command for object without authority."

//this happens every time my enemy spawner tries to spawn an enemy when the //game is hosted by a built game and every player is considered as a client //The enemy prefab still gets spawned and moves as intended

"SpawnObject for EnemyUpRight(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server." 

//When an enemy bullet hits a player, instead of getting damaged an error shows up

"RPC Function RpcTakeDamage called on client."
1

1 Answers

0
votes

The summary of your problems are

"Trying to send command for object without authority."

The biggest part of your errors come from your spawner probably. Your spawner is not your server player, and the only element with authority on u-net scenes is the server player.

So you have 2 options:

  1. Try to put your spawning function on your player (which by the way should be a [Command] function!). I suggest you to read my answer on: Instantiated prefab scale is not displayed correctly on client

2.Switch authorities on the scene, where I suggest another answer to better understanding: Problem in authority shifting of non-player object

Hope it helps!