Search Unity

UNET - Picking up items

Discussion in 'UNet' started by GameDevJon, Aug 2, 2017.

  1. GameDevJon

    GameDevJon

    Joined:
    Jul 21, 2017
    Posts:
    25
    Hey guys,

    My client and server are separate projects. Essentially my client is acting as a shell and just handles the visual for the server.

    I'm working on my item system. Currently, the server can spawn an item on the server, and it will show up for the client. Also, using SyncVar I am able to bring the item deffinition/stats from the server into the client.

    How would I go about collecting this item? For example, If I ray cast and click the object, how do I send that message to the server with the item they clicked?

    the item on the client/server is a network behavior.

    I have looked into Commands, but I don't see how the command will be ran on the server due to having separate projects.

    Thanks!
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    It won't be, unless you have identical Cmd code in both projects.
    You need to have identical class structure, OR use messages with handlers attached to the specific (short) id.
     
    TwoTen likes this.
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If you are using the really HLAPI stuff. Different projects is not really optimal, sadly. (I know it's beautiful to code in the super HLAPI stuff). But as VergiUa said. You can have idential NetworkBehaviour structure (Which is prolly what you want). So then it will work. So on the server project. You create all the RPC's but they have nothing in them. Same for Cmds on client
     
  4. GameDevJon

    GameDevJon

    Joined:
    Jul 21, 2017
    Posts:
    25
    Right. I'm working with the LLAPI.

    So that was my thought...Currently for the login system, I am using the MessageBase Class.

    It feels like i'm doing things twice. I guess this is normal.

    For my login system....I have a loginRequest message base with identical structure on the client/server.

    I guess I would continue sending MessageBase type classes to and from the server?

    So for picking up an item...I would have an OnItemClick message base class, and then send the data of the object to the server, who would then process it and add it to the inventory on the server?

    Is this the best way to do it?

    I feel like i'll have about 500 message base classes by the time i'm done.
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    You can utilize the same message base for multiple purposes.
    Just make sure you're attaching proper handlers and you're good to go.

    But in a nutshell, yes, you would need to have those classes in both projects.
     
    TwoTen likes this.
  6. GameDevJon

    GameDevJon

    Joined:
    Jul 21, 2017
    Posts:
    25
    Thanks mate. After talking with @TwoTen

    I've realized i'm not using the low level api like I thought. I'm using the middle level API. I can continue doing things with the messageBase class, but ultimately, I think I need to get lower into the Low Level API and convert everything to the LLAPI so I can have a better understanding of the network system as well as more control overal.
     
    TwoTen likes this.