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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Unity Multiplayer Sending commands from clients on non-player object?

Discussion in 'Multiplayer' started by CaretCaret, Jun 13, 2015.

  1. CaretCaret

    CaretCaret

    Joined:
    Mar 7, 2015
    Posts:
    9
    Hello, first time poster here.

    I'm trying to get a hang of the new multiplayer stuff from 5.1 and so far I'm very impressed. I would call it easy to implement but a bit hard to grasp. Anywho...

    So I have this non-player object that is controlled/owned by the server and is synced to the clients. I am then trying to run a command from a non-server client on said object.

    As I understand it I am only allowed to send commands on the clients own player, so is there some other way to do this?
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    In the HLAPI non-player objects are owned by the server. You can't use a command from a non-player object. You could have the local player on that client do the command, then route it to the object on the server.
     
  3. CaretCaret

    CaretCaret

    Joined:
    Mar 7, 2015
    Posts:
    9
    Ok, that will probably work, but I would prefer not to have it set up that way, but I assume that's the only way to do it then?
    Thank you for the help!
     
  4. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,254
    What sort of command do you need the NPC to perform that requires it must originate on the client? Probably better if most of the simulation, i.e. the game logic for things like NPC AI, takes place on the server, and is then sent to the clients.
     
  5. CaretCaret

    CaretCaret

    Joined:
    Mar 7, 2015
    Posts:
    9
    Right now I have bullets that are instantiated locally for a client and then I just want it to send a damage event on the enemy it hit. (its a 2d game and the bullets are gameobjects)
    My thinking was that since there will be so many bullets and that I want to avoid having to depend on the server to fire bullets, that each client is responsible for their bullet and only reports what they hit and doesn't sync each bullet.
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    That is not a very secure model Any client could send fake damage events to the server.

    Another model would be to fire the bullets on the clients and on the server, and only have the server version of the bullets do damage events. Look at the Presentation10 sample, and the Unet presentation for an example of doing damage like that:

    http://forum.unity3d.com/threads/networking-presentation-and-sample-project.331980/