Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Server Side AI with Unet

Discussion in 'UNet' started by maxzoech, Jul 18, 2016.

  1. maxzoech

    maxzoech

    Joined:
    Dec 23, 2013
    Posts:
    23
    Hi everyone,
    I am currently working on a multiplayer project and I was curious if it is possible to simulate enemies on the server.
    Yours,
    Max
     
  2. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Yep. All my NPCs and MOBs are server-side entities (as are PCs really), but with AI scripts to control their movements and actions.
     
  3. maxzoech

    maxzoech

    Joined:
    Dec 23, 2013
    Posts:
    23
    How did you do that? I see no way to execute code on the server…
     
  4. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    That depends upon your game architecture. I run separate servers that are Unity instances - that makes it very easy to have the code needed running on them.

    If you're using the part of uNet where one of the players is the server, I think you need to run network code on just the server using ServerAttributes. There's also some info at Clients & Servers.
     
  5. maxzoech

    maxzoech

    Joined:
    Dec 23, 2013
    Posts:
    23
    Ok, thanks! But it is not directly possible through UNET?
     
  6. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Perhaps someone else can come in on this, as my experience with uNet is limited to dedicated servers; I'm not familiar with the attributes and rpcs and their execution.
     
  7. Megaphone_

    Megaphone_

    Joined:
    Mar 23, 2016
    Posts:
    41
    Any logic you would want the server to run you would only need to execute the code like this...

    [Server] void ServerFnc() {
    Code
    }