Good Place. Good Things. Good Time.

Why does the object spawns only on client?

In my game I have an object, let say food, that whoever consumes it, that player will spawn one more element. I am checking collision in Update.

The following code is working fine on server side, but the object is not spawning. Although, it is spawning on local client but it is not updating on server.

Here is my code:

// This function is called on Update
private void CheckForFood(Vector3 snakePartPosToBeInitialize,Vector3 headPos)
{
    if(_food != null)
    {
        if (_food.transform.position == headPos)
        {
            UiControllerCS.UI.showScore();
            GameObject obj = Instantiate(snakePart, snakePartPosToBeInitialize, Quaternion.identity) as GameObject;
            currPartOfSnake += 1;
            obj.name = "" + currPartOfSnake;
            obj.transform.parent = gameObject.transform;
            tail.Add(obj);
            NetworkServer.SpawnWithClientAuthority(obj , connectionToClient);
        }
    }
}

I am getting the following error :

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

Why does the object spawns only on client?

Search more articles here: Why does the object spawns only on client?

Read original article here: Why does the object spawns only on client?



Disclaimers and Denial of responsibility..!

Denial of responsibility! TheTopMag.com is an automatic aggregator of all media around the world. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – jamesonline999@gmail.com . The content will be deleted within 72 hours.
You might also like
Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.