Search Unity

ClientRpc with templates not supported ?

Discussion in 'Multiplayer' started by razdolbator, Jun 18, 2015.

  1. razdolbator

    razdolbator

    Joined:
    Aug 2, 2014
    Posts:
    4
    Doesn't seem to work. Any chance this will change in the near future ?

    [ClientRpc]
    void RpcGoto<T>() where T : GameNetworkBehaviour {
    ChangePrimaryProtocol<T>();
    _sceneProtocol.InitClientView();
    }
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    no. There are error messages that prevent this from even compiling in the next patch release.
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    @seanr why is this an unsupported scenario ?

    The client RPC call (i assume) generates some wrapper code that calls this method on the client. Wouldn't it be a similar scenario to be able to call the generic method in a similar way ?
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Would this actually be useful? I have no idea what pasted code snippet is trying to accomplish.

    This wouldn't be possible in the current system without significant changes to the way code generation works. Each ClientRpc now maps to set of code and data that is generated from the function signature. If that supported generics, then that set of code and data would be related to typed instances of that ClientRpc found anywhere throughout the project, and the code and data would have to be specialized for that type.
     
  5. razdolbator

    razdolbator

    Joined:
    Aug 2, 2014
    Posts:
    4
    If this is not supported, it makes use of generics almost useless inside a class with rpc/commands since you need to "help" it with ifs or switch statements.

    This function allows me to do something like ChangeScene<SceneClass> without having to enumerate anything.
     
  6. razdolbator

    razdolbator

    Joined:
    Aug 2, 2014
    Posts:
    4
    I'm sorry if my question may be dumb, I'm new to c# and don't know too much about the unity framework but maybe it is a possible workaround if the ClientRpc and Command attributes, if used with templates will cause the methods and all calls to them to be renamed at compile time to something like method_type ?