[Solved] Composition for Player Prefab(network)

Hi, I need some explain how I can split my Player Pfreab class into small pieces. For example my Player class contains 20 Commands 20 Rpc and 20 TargetRpc methods, it’s very hard to navigate through them.

I want so split it by class “containers” like PlayerCommnds, PlayerRpcs, PlayerTargetRpc.

I tryied to create field in Player class, move method into this field type and call, but it causes diffrent network errors. When I revert method back to Player it’s again work great.

What is correct way to split Player when it growth to 999 methods?

public class Player : NetworkBehaviour
    {
        public ServerCommands ServerCommands;
     }

public class ServerCommands
    {
        [Command]
        public void CmdStartGame(NetworkIdentity identity)
        {
             // Do magic
        }


public class GameManager
{
      Player findLocalPlayer = ...;
      findLocalPlayer.ServerCommands.CmdStartGame(findLocalPlayer .NetworkIdentity)
}

These different classes need to be in their own separate files with the same filename as the new class, they all need to inherit from NetworkBehaviour, and they all separately need to be attached to the same Player GameObject prefab.

Thank you, my fault was that I thinking only from the code side and forgot to add those scripts to Player prefab.

1 Like