Search Unity

Discerning between server and client instance of object

Discussion in 'Multiplayer' started by EAVN, Feb 20, 2017.

  1. EAVN

    EAVN

    Joined:
    Feb 20, 2017
    Posts:
    3
    I am having a difficult time setting up AI units in my multiplayer networked game. Ultimately, I intend to run the movement logic for all AIs in my game on the server only, and update the clients via an attached network transform component.

    I have attempted to use a [Server] attribute on the code being run on my AI units. However, when running a client connected to a built server instance in the Unity environment, I get a series of warnings that a [Server] function was called on a client, which leads me to believe that the [Server] attribute isn't really stopping code from being run on clients.

    I've also attempted to use the function Network.isServer, and Network.isClient attached to the code in my AI characters to make a distinction between objects on servers and clients, but they always return false in all cases. The documentation on these two functions is somewhat lacking, so I'm not really certain if this is the proper way to utilize them anyway.

    What is the most common method of discerning between Server and Client instances in Unity Networking? Are there other functions or methods for this purpose besides what I have referenced here?
     
  2. EAVN

    EAVN

    Joined:
    Feb 20, 2017
    Posts:
    3
    I fixed my problem.

    The reason isServer was not working is because I was attempting to use it on a child object. The parent had a NetworkTransform, and several NetworkTransformChild components for the child AI objects. I had assumed that the NetworkTransformChild components would make the instantiated object active on the server, but this is apparently not the case.

    This raises other questions about how to keep my hierarchy organized in my game, but my main issue has been solved.