Doc Home > Networking
The Third Person Controller supports Unity's networking solution introduced with Unity 5.1. Networking is a complex topic so it is highly recommended that you first go through Unity's networking documentation before continuing. The Third Person Controller network integration uses an authoritative server on Unity's HLAPI layer. Unity 5.1.2 or later is required for the networking integration to work.
There are two extra steps to make your character a networked character. The first step is to add the NetworkIdentity, NetworkTransform, and NetworkAnimator components to your character. The Character Builder will automatically add these components if Is Networked Character is enabled within the first step of the wizard. The second step is to add the ENABLE_MULTIPLAYER compiler definition to your PlayerSettings. This definition can be added manually or automatically added by clicking the "Add Multiplayer Symbol" button within the RigidbodyCharacterController component:
Once your character is setup the final step is to add two networking components to your scene GameObjects. The first component that should be added is the NetworkEventManager. This component should be added instead of the Unity NetworkManager component and can be added to any GameObject within your scene. The NetworkEventManager inherits from NetworkManager and allows the EventHandler to notify interested components about network events. You will also need to add the NetworkIdentity component to your Game GameObject, which was created with "Setup Scene" from the Start Window.
If you are converting an already created character to a networked game you'll want to add the following four components to your character: NetworkMonitor, NetworkIdentity, NetworkTransform, and NetworkAnimator.
The Third Person Controller includes a demo scene to help get you started with networking. This demo scene can be setup by:
- Import the Third Person Controller into a Unity 5.1.2+ project
- Import the source code
- Open the Third Person Controller/Demos/Network scene
- Add the ENABLE_MULTIPLAYER symbol (see above)
- Add the Explosion, Grenade, and Rocket prefabs from the Third Person Controller/Demos/Network/Prefabs directory to the Object Pool. This must be done manually because when the Third Person Controller is submitted to the Asset Store it does not have the ENABLE_MULTIPLAYER symbol defined. See the image below for an example.
The network scene was created using the steps above. One thing to note about this scene is that there are two different sets of spawnable prefab registration locations. The first set is specified within the Unity NetworkManager component:
And the second set is specified within the ObjectPool component:
If your prefabs can be spawned by the ObjectPool, then the prefabs should be registered by the ObjectPool component. From the sample scene the Rocket, Explosion, and Grenade prefabs are spawned using the ObjectPool. This does not include every object spawned by the ObjectPool, only those that should be spawned over the network. For example, a muzzle flash does not need to be spawned over the network so it does not need to be a registered prefab. Any prefabs spawned over the network which do not use the ObjectPool should be specified within the NetworkManager component.
<- AI Integration